ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zquest.cpp
Date: 2025-09-03 02:14:11
Exec Total Coverage
Lines: 2261 14834 15.2%
Functions: 49 742 6.6%
Branches: 1400 11055 12.7%

Line Branch Exec Source
1 #include "allegro/gui.h"
2 #include "base/files.h"
3 #include "base/mapscr.h"
4 #include "dialog/edit_region.h"
5
6 #include <memory>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <cstring>
10 #include <sstream>
11 #include <ctype.h>
12 #include <assert.h>
13 #include <time.h>
14 #include <vector>
15 #include <filesystem>
16 #include <base/new_menu.h>
17
18 #include "dialog/info_lister.h"
19 #ifdef __APPLE__
20 // malloc.h is deprecated, but malloc also lives in stdlib
21 #include <stdlib.h>
22 #else
23 #include <malloc.h>
24 #endif
25
26 #include "zalleg/zalleg.h"
27 #include "base/qrs.h"
28 #include "base/dmap.h"
29 #include "base/msgstr.h"
30 #include "base/packfile.h"
31 #include "base/cpool.h"
32 #include "base/autocombo.h"
33 #include "base/render.h"
34 #include "base/version.h"
35 #include "zq/autocombo/autopattern_base.h"
36 #include "zq/autocombo/pattern_basic.h"
37 #include "zq/autocombo/pattern_flatmtn.h"
38 #include "zq/autocombo/pattern_fence.h"
39 #include "zq/autocombo/pattern_cakemtn.h"
40 #include "zq/autocombo/pattern_relational.h"
41 #include "zq/autocombo/pattern_dungeoncarve.h"
42 #include "zq/autocombo/pattern_dormtn.h"
43 #include "zq/autocombo/pattern_tiling.h"
44 #include "zq/autocombo/pattern_replace.h"
45 #include "zq/autocombo/pattern_denseforest.h"
46 #include "zq/autocombo/pattern_extend.h"
47 #include "zq/render_hotkeys.h"
48 #include "zq/render_minimap.h"
49 #include "zq/render_tooltip.h"
50 #include "base/misctypes.h"
51 #include "parser/Compiler.h"
52 #include "base/zc_alleg.h"
53 #include "particles.h"
54 #include "dialog/combopool.h"
55 #include "dialog/alert.h"
56 #include "dialog/alertfunc.h"
57 #include "zq/gui/edit_autocombo.h"
58
59 #include <al5_img.h>
60 #include <loadpng.h>
61 #include <fmt/format.h>
62
63 #include "dialog/cheat_codes.h"
64 #include "dialog/set_password.h"
65 #include "dialog/foodlg.h"
66 #include "dialog/quest_rules.h"
67 #include "dialog/script_rules.h"
68 #include "dialog/headerdlg.h"
69 #include "dialog/ffc_editor.h"
70 #include "dialog/screen_data.h"
71 #include "dialog/edit_dmap.h"
72 #include "dialog/compilezscript.h"
73 #include "dialog/screen_enemies.h"
74 #include "dialog/enemypattern.h"
75 #include "dialog/sfxdata.h"
76 #include "dialog/mapstyles.h"
77 #include "dialog/externs.h"
78
79 #include "base/gui.h"
80 #include "gui/jwin_a5.h"
81 #include "gui/jwin.h"
82 #include "zc_list_data.h"
83 #include "gui/editbox.h"
84 #include "zq/zq_misc.h"
85 #include "zq/zq_tiles.h" // tile and combo code
86
87 #include "zq/zquest.h"
88 #include "zq/ffasm.h"
89 #include "zq/render.h"
90
91 // the following are used by both zelda.cc and zquest.cc
92 #include "base/zdefs.h"
93 #include "base/qrs.h"
94 #include "tiles.h"
95 #include "base/colors.h"
96 #include "base/qst.h"
97 #include "base/zsys.h"
98 #include "base/zapp.h"
99 #include "base/process_management.h"
100 #include "play_midi.h"
101 #include "sound/zcmusic.h"
102
103 #include "midi.h"
104 #include "sprite.h"
105 #include "fontsdat.h"
106 #include "base/jwinfsel.h"
107 #include "zq/zq_class.h"
108 #include "subscr.h"
109 #include "zq/zq_subscr.h"
110 #include "zc/ffscript.h"
111 #include "gui/EditboxNew.h"
112 #include "sfx.h"
113 #include "zq/zq_custom.h" // custom items and guys
114 #include "zq/zq_strings.h"
115 #include "zq/questReport.h"
116 #include <fstream>
117 #include "drawing.h"
118 #include "zconsole/ConsoleLogger.h"
119 #include "colorname.h"
120 #include "zq/zq_hotkey.h"
121 #include "zq/package.h"
122 #include "zq/zq_files.h"
123 #include "music_playback.h"
124
125 //Windows mmemory tools
126 #ifdef _WIN32
127 #include <windows.h>
128 #include <stdio.h>
129 #include <psapi.h>
130 #pragma comment(lib, "psapi.lib") // Needed to avoid linker issues. -Z
131 #endif
132
133 #ifdef __EMSCRIPTEN__
134 #include <emscripten/emscripten.h>
135 #endif
136
137 #define MIDI_TRACK_BUFFER_SIZE 50
138 extern CConsoleLoggerEx parser_console;
139
140 using ZScript::disassembled_script_data;
141 void write_script(vector<shared_ptr<ZScript::Opcode>> const& zasm, string& dest,
142 bool commented, map<string,disassembled_script_data>* scr_meta_map);
143
144 namespace fs = std::filesystem;
145
146 #if defined(ALLEGRO_WINDOWS)
147 static const char *data_path_name = "win_data_path";
148 static const char *midi_path_name = "win_midi_path";
149 static const char *image_path_name = "win_image_path";
150 static const char *tmusic_path_name = "win_tmusic_path";
151 static const char *last_quest_name = "win_last_quest";
152 static const char *qtname_name = "win_qtname%d";
153 static const char *qtpath_name = "win_qtpath%d";
154 #elif defined(ALLEGRO_LINUX)
155 static const char *data_path_name = "linux_data_path";
156 static const char *midi_path_name = "linux_midi_path";
157 static const char *image_path_name = "linux_image_path";
158 static const char *tmusic_path_name = "linux_tmusic_path";
159 static const char *last_quest_name = "linux_last_quest";
160 static const char *qtname_name = "linux_qtname%d";
161 static const char *qtpath_name = "linux_qtpath%d";
162 #elif defined(__APPLE__)
163 static const char *data_path_name = "macosx_data_path";
164 static const char *midi_path_name = "macosx_midi_path";
165 static const char *image_path_name = "macosx_image_path";
166 static const char *tmusic_path_name = "macosx_tmusic_path";
167 static const char *last_quest_name = "macosx_last_quest";
168 static const char *qtname_name = "macosx_qtname%d";
169 static const char *qtpath_name = "macosx_qtpath%d";
170 #endif
171
172 #include "base/win32.h"
173
174 #include "zq/zq_init.h"
175 #include "zq/zq_doors.h"
176 #include "zq/zq_cset.h"
177 #include "zinfo.h"
178
179 #ifdef _MSC_VER
180 #include <crtdbg.h>
181
182 #endif
183
184 // MSVC fix
185 #if _MSC_VER >= 1900
186 FILE _iob[] = { *stdin, *stdout, *stderr };
187 extern "C" FILE * __cdecl __iob_func(void) { return _iob; }
188 #endif
189
190 extern byte monochrome_console;
191
192 #include "zconsole/ConsoleLogger.h"
193
194 extern CConsoleLoggerEx zscript_coloured_console;
195
196 uint8_t console_is_open = 0;
197 bool is_zq_replay_test = false;
198
199 #include "base/util.h"
200
201 #ifdef __EMSCRIPTEN__
202 #include "base/emscripten_utils.h"
203 #endif
204
205 using namespace util;
206
207 using std::vector;
208 using std::map;
209 using std::stringstream;
210
211 12 FFScript FFCore;
212
213 void load_size_poses();
214 void do_previewtext();
215 bool do_slots(vector<shared_ptr<ZScript::Opcode>> const& zasm,
216 map<string, disassembled_script_data> &scripts, int assign_mode);
217
218 int32_t startdmapxy[6] = {-1000, -1000, -1000, -1000, -1000, -1000};
219 bool cancelgetnum=false;
220
221 int32_t tooltip_timer=0, tooltip_maxtimer=30, tooltip_current_ffc=0;
222 int32_t combobrushoverride=-1;
223 ComboPosition mouse_combo_pos;
224
225 int32_t original_playing_field_offset=0;
226 12 int32_t playing_field_offset=original_playing_field_offset;
227 int32_t passive_subscreen_height=56;
228
229 bool disable_saving=false, OverwriteProtection;
230 bool halt=false;
231 bool show_sprites=true;
232 bool show_hitboxes = false;
233 bool zq_ignore_item_ownership = true;
234
235 // Used to find FFC script names
236 vector<string> asffcscripts;
237 vector<string> asglobalscripts;
238 vector<string> asitemscripts;
239 vector<string> asnpcscripts;
240 vector<string> aseweaponscripts;
241 vector<string> aslweaponscripts;
242 vector<string> asplayerscripts;
243 vector<string> asdmapscripts;
244 vector<string> asscreenscripts;
245 vector<string> asitemspritescripts;
246 vector<string> ascomboscripts;
247 vector<string> asgenericscripts;
248 vector<string> assubscreenscripts;
249
250 vector<string> ZQincludePaths;
251
252 int32_t CSET_SIZE = 16;
253 int32_t CSET_SHFT = 4;
254 //editbox_data temp_eb_data;
255 /*
256 #define CSET(x) ((x)<<CSET_SHFT)
257 #define csBOSS 14
258 */
259
260 /*
261 enum { m_block, m_coords, m_flags, m_guy, m_warp, m_misc, m_layers,
262 m_menucount };
263 */
264 void update_combo_cycling();
265 void update_freeform_combos();
266
267 /*
268 #define MAXMICE 14
269 #define MAXARROWS 8
270 #define SHADOW_DEPTH 2
271 */
272 int32_t coord_timer=0, coord_frame=0;
273 int32_t blackout_color, zq_screen_w, zq_screen_h;
274 int32_t draw_mode=0;
275
276 12 size_and_pos minimap;
277 12 size_and_pos real_minimap;
278
279 12 size_and_pos minimap_zoomed;
280 12 size_and_pos real_minimap_zoomed;
281
282 12 size_and_pos map_page_bar[9];
283 int32_t mappage_count = 9;
284
285 12 size_and_pos combolist[MAX_COMBO_COLS];
286 12 size_and_pos combolistscrollers[MAX_COMBO_COLS];
287 int32_t num_combo_cols = MAX_COMBO_COLS;
288
289 static bool zoom_in_btn_disabled;
290 static bool zoom_out_btn_disabled;
291 12 size_and_pos zoominbtn;
292 12 size_and_pos zoomoutbtn;
293 12 size_and_pos compactbtn;
294 12 size_and_pos mainbar;
295
296 12 size_and_pos screrrorpos;
297
298 12 size_and_pos comboaliaslist[MAX_COMBO_COLS];
299 12 size_and_pos comboalias_preview;
300 12 size_and_pos combopool_preview;
301 12 size_and_pos combopool_prevbtn;
302
303 12 size_and_pos combo_merge_btn;
304
305 12 size_and_pos combo_preview;
306 12 size_and_pos combo_preview2;
307 12 size_and_pos combo_preview_text1;
308 12 size_and_pos combo_preview_text2;
309 12 size_and_pos combolist_window;
310 12 size_and_pos drawmode_btn;
311 12 size_and_pos main_panel;
312 12 size_and_pos squares_panel;
313 12 size_and_pos preview_panel;
314 12 size_and_pos layer_panel;
315 12 size_and_pos preview_text;
316
317 12 size_and_pos favorites_window;
318 12 size_and_pos favorites_list;
319 12 size_and_pos favorites_x;
320 12 size_and_pos favorites_infobtn;
321 12 size_and_pos favorites_zoombtn;
322 12 size_and_pos favorites_pgleft;
323 12 size_and_pos favorites_pgright;
324
325 12 size_and_pos commands_window;
326 12 size_and_pos commands_list;
327 12 size_and_pos commands_x;
328 12 size_and_pos commands_infobtn;
329 12 size_and_pos commands_zoombtn;
330 12 size_and_pos commands_txt;
331
332 12 size_and_pos squarepanel_swap_btn;
333 12 size_and_pos squarepanel_up_btn;
334 12 size_and_pos squarepanel_down_btn;
335 12 size_and_pos itemsqr_pos;
336 12 size_and_pos flagsqr_pos;
337 12 size_and_pos stairsqr_pos;
338 12 size_and_pos warparrival_pos;
339 12 size_and_pos warpret_pos[4];
340 12 size_and_pos enemy_prev_pos;
341
342 12 size_and_pos txtoffs_single;
343 12 size_and_pos txtoffs_double_1;
344 12 size_and_pos txtoffs_double_2;
345 int32_t panel_align = 1;
346
347 int32_t command_buttonwidth = 88;
348 int32_t command_buttonheight = 19;
349
350 int32_t layerpanel_buttonwidth = 58;
351 int32_t layerpanel_buttonheight = 16;
352
353 int32_t layerpanel_checkbox_hei = 13;
354 int32_t layerpanel_checkbox_wid = 13;
355
356 int32_t favorite_combos[MAXFAVORITECOMBOS];
357 byte favorite_combo_modes[MAXFAVORITECOMBOS];
358 bool ShowFavoriteComboModes;
359 byte FavoriteComboPage;
360
361 char comboprev_buf[512] = {0};
362 char comboprev_buf2[512] = {0};
363 FONT* txfont;
364
365 const char *roomtype_string[MAXROOMTYPES] =
366 {
367 "(None)","Special Item","Pay for Info","Secret Money","Gamble",
368 "Door Repair","Red Potion or Heart Container","Feed the Goriya","Triforce Check",
369 "Potion Shop","Shop","More Bombs","Leave Money or Life","10 Rupees",
370 "3-Stair Warp","Ganon","Zelda", "-<item pond>", "1/2 Magic Upgrade", "Learn Slash", "More Arrows","Take One Item"
371 };
372
373 const char *catchall_string[MAXROOMTYPES] =
374 {
375 "Generic Catchall","Special Item","Info Type","Amount","Generic Catchall","Repair Fee","Generic Catchall","Generic Catchall","Generic Catchall","Shop Type",
376 "Shop Type","Price","Price","Generic Catchall","Warp Ring","Generic Catchall","Generic Catchall", "Generic Catchall", "Generic Catchall",
377 "Generic Catchall", "Price","Shop Type","Bottle Shop Type"
378 };
379
380 #define MAXPOOLCOMBOS MAXFAVORITECOMBOS
381
382 struct cmbdat_pair
383 {
384 int32_t data;
385 byte cset;
386 15120 cmbdat_pair() { clear(); }
387 25200 void clear()
388 {
389 25200 data = -1;
390 25200 cset = 0;
391 25200 }
392 bool valid() const
393 {
394 return data > -1;
395 }
396 };
397 bool pool_dirty=true;
398 12 cmbdat_pair pool_combos[MAXPOOLCOMBOS];
399 static std::vector<byte> pool;
400
401 bool pool_valid()
402 {
403 if(pool_dirty)
404 {
405 pool.clear();
406 for(auto q = 0; q < MAXPOOLCOMBOS; ++q)
407 {
408 if(pool_combos[q].valid())
409 pool.push_back(q);
410 }
411 pool_dirty = false;
412 }
413 return pool.size() > 0;
414 }
415 cmbdat_pair const& get_pool_combo()
416 {
417 if(!pool_valid()) return pool_combos[0];
418 auto ind = zc_rand(pool.size()-1);
419 return pool_combos[pool.at(ind)];
420 }
421
422 int32_t mouse_scroll_h;
423
424 // 'mapscreen' refers to the area of the editor where the screen is drawn.
425 int32_t mapscreen_x, mapscreen_y, showedges, showallpanels;
426 // The scale of the entire mapscreen area. This varies based on compact/extended mode.
427 static int mapscreen_screenunit_scale;
428 // The scale of an individual screen being drawn. This is `mapscreen_screenunit_scale / Map.getViewSize()`.
429 static double mapscreen_single_scale;
430 // 4 is roughly the largest value where things render okay. Beyond that, our low bitmap resolution results in tons
431 // of downsampling. Let users go to 16 anyway.
432 static int mapscreen_num_screens_to_draw_max = 16;
433 // The valid layers for the current screen(s).
434 static bool mapscreen_valid_layers[6];
435
436 struct VisibleScreen
437 {
438 int dx, dy;
439 int xoff, yoff;
440 mapscr* scr;
441 int screen;
442 };
443 static std::vector<VisibleScreen> visible_screens;
444 static VisibleScreen* active_visible_screen = nullptr;
445
446 static void set_active_visible_screen(mapscr* scr)
447 {
448 active_visible_screen = nullptr;
449 for (auto& visible_screen : visible_screens)
450 {
451 if (visible_screen.scr == scr)
452 {
453 active_visible_screen = &visible_screen;
454 break;
455 }
456 }
457 }
458
459 static ComboPosition get_mapscreen_mouse_combo_pos()
460 {
461 int startxint = mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
462 int startyint = mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
463 int cx = (gui_mouse_x()-startxint)/(16*mapscreen_single_scale);
464 int cy = (gui_mouse_y()-startyint)/(16*mapscreen_single_scale);
465 return ComboPosition{cx, cy};
466 }
467
468 static void refresh_visible_screens()
469 {
470 int num_screens = Map.getViewSize();
471 int screen_width = mapscreenbmp->w * mapscreen_single_scale;
472 int screen_height = mapscreenbmp->h * mapscreen_single_scale;
473
474 visible_screens.clear();
475 for (int dx = 0; dx < num_screens; dx++)
476 {
477 for (int dy = 0; dy < num_screens; dy++)
478 {
479 int mx = Map.getViewScr()%16 + dx;
480 int my = Map.getViewScr()/16 + dy;
481 if (mx < 0 || mx >= 16 || my < 0 || my >= 9)
482 continue;
483
484 int screen = Map.getViewScr() + dx + dy * 16;
485 if (screen >= MAPSCRS)
486 continue;
487
488 mapscr* scr = Map.Scr(screen);
489 int offx = dx * screen_width;
490 int offy = dy * screen_height;
491 visible_screens.emplace_back(VisibleScreen{dx, dy, offx, offy, scr, screen});
492 }
493 }
494
495 for (int i = 0; i < 6; i++)
496 {
497 mapscreen_valid_layers[i] = false;
498 for (auto& vis_screen : visible_screens)
499 {
500 mapscreen_valid_layers[i] |= vis_screen.scr->layermap[i] > 0;
501 }
502 }
503 }
504
505 int32_t readsize, writesize;
506 bool fake_pack_writing=false;
507
508 int32_t showxypos_x;
509 int32_t showxypos_y;
510 int32_t showxypos_w;
511 int32_t showxypos_h;
512 int32_t showxypos_color;
513 int32_t showxypos_ffc=-1000;
514 bool showxypos_icon=false;
515
516 int32_t showxypos_cursor_x;
517 int32_t showxypos_cursor_y;
518 bool showxypos_cursor_icon=false;
519 int32_t showxypos_cursor_color;
520 bool showxypos_dummy = false;
521
522 bool canfill=true; //to prevent double-filling (which stops undos)
523 int32_t lens_hint_item[MAXITEMS][2]; //aclk, aframe
524 int32_t lens_hint_weapon[MAXWPNS][5]; //aclk, aframe, dir, x, y
525 //int32_t mode, switch_mode, orig_mode;
526 int32_t tempmode=GFX_AUTODETECT;
527 RGB_MAP zq_rgb_table;
528 COLOR_MAP trans_table, trans_table2;
529 MIDI *song=NULL;
530 BITMAP *menu1, *menu3, *mapscreenbmp, *tmp_scr, *screen2, *mouse_bmp[MOUSE_BMP_MAX][4], *mouse_bmp_1x[MOUSE_BMP_MAX][4], *icon_bmp[ICON_BMP_MAX][4], *flag_bmp[16][4], *select_bmp[2], *dmapbmp_small, *dmapbmp_large;
531 BITMAP *arrow_bmp[MAXARROWS],*brushbmp, *brushscreen; //*brushshadowbmp;
532 byte *colordata=NULL, *trashbuf=NULL;
533 itemdata *itemsbuf;
534 wpndata *wpnsbuf;
535 comboclass *combo_class_buf;
536 guydata *guysbuf;
537 item_drop_object item_drop_sets[MAXITEMDROPSETS];
538 12 newcombo curr_combo;
539 PALETTE RAMpal;
540 midi_info Midi_Info;
541 bool zq_showpal=false;
542 bool is_compact = false;
543
544 int pixeldb = 1;
545 int infobg = 1;
546 bool large_merged_combopane = false;
547 bool compact_merged_combopane = true;
548 bool large_zoomed_fav = false;
549 bool compact_zoomed_fav = true;
550 bool large_zoomed_cmd = false;
551 bool compact_zoomed_cmd = true;
552
553 bool compact_square_panels = false;
554 int compact_active_panel = 0;
555
556 int combo_col_scale = 1;
557
558 std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
559 script_data *ffscripts[NUMSCRIPTFFC];
560 script_data *itemscripts[NUMSCRIPTITEM];
561 script_data *guyscripts[NUMSCRIPTGUYS];
562 script_data *lwpnscripts[NUMSCRIPTWEAPONS];
563 script_data *ewpnscripts[NUMSCRIPTWEAPONS];
564 script_data *globalscripts[NUMSCRIPTGLOBAL];
565 script_data *genericscripts[NUMSCRIPTSGENERIC];
566 script_data *playerscripts[NUMSCRIPTHERO];
567 script_data *screenscripts[NUMSCRIPTSCREEN];
568 script_data *dmapscripts[NUMSCRIPTSDMAP];
569 script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
570 script_data *comboscripts[NUMSCRIPTSCOMBODATA];
571 script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
572
573 extern string zScript;
574 char zScriptBytes[512];
575 char zLastVer[512] = { 0 };
576 SAMPLE customsfxdata[WAV_COUNT];
577 uint8_t customsfxflag[WAV_COUNT>>3];
578 int32_t sfxdat=1;
579
580 int32_t onImport_ComboAlias();
581 int32_t onExport_ComboAlias();
582
583 void set_console_state();
584
585 void clearConsole()
586 {
587 if(!console_is_open) return;
588 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
589 zscript_coloured_console.gotoxy(0,0);
590 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
591 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
592 }
593
594 void initConsole()
595 {
596 if(console_is_open) return;
597 console_is_open = 1;
598 set_console_state();
599 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200);
600 clearConsole();
601 }
602
603 11 void killConsole()
604 {
605
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(!console_is_open) return;
606 console_is_open = 0;
607 set_console_state();
608 zscript_coloured_console.kill();
609 11 }
610
611 int toggleConsole()
612 {
613 console_is_open ? killConsole() : initConsole();
614 zc_set_config("zquest","open_debug_console",console_is_open?1:0);
615 return D_O_K;
616 }
617
618 int showHotkeys()
619 {
620 hotkeys_toggle_display(!hotkeys_is_active());
621 return D_O_K;
622 }
623
624 typedef int32_t (*intF)();
625 typedef struct command_pair
626 {
627 char name[80];
628 int32_t flags;
629 intF command;
630 } command_pair;
631
632 extern map_and_screen map_page[MAX_MAPPAGE_BTNS];
633
634 int32_t do_OpenQuest()
635 {
636 return onOpen();
637 }
638
639 int32_t do_NewQuest()
640 {
641 //clear the panel recent screen buttons to prevent crashes from invalid maps
642 for ( int32_t q = 0; q < 9; q++ )
643 {
644 map_page[q].map = 0;
645 map_page[q].screen = 0;
646 }
647 Map.setCurrMap(0);
648 Map.setCurrScr(0);
649 return onNew();
650 }
651
652 extern int CheckerCol1, CheckerCol2;
653 int32_t alignment_arrow_timer=0;
654 int32_t Flip=0,Combo=0,CSet=2,current_combolist=0,current_comboalist=0,current_cpoollist=0,current_cautolist=0,current_mappage=0;
655 int32_t Flags=0,Flag=0,menutype=(m_block);
656 int MouseScroll = 0, SavePaths = 0, CycleOn = 0, ShowGrid = 0, ShowScreenGrid = 0, ShowRegionGrid = 0, GridColor = 15, ShowCurScreenOutline = 1,
657 CmbCursorCol = 15, TilePgCursorCol = 15, CmbPgCursorCol = 15, TTipHLCol = 13,
658 TileProtection = 0, ComboProtection = 0, NoScreenPreview = 0, MMapCursorStyle = 0,
659 LayerDitherBG = -1, LayerDitherSz = 2, RulesetDialog = 0,
660 EnableTooltips = 0, TooltipsHighlight = 0, ShowFFScripts = 0, ShowSquares = 0,
661 ShowFFCs = 0, ShowInfo = 0, skipLayerWarning = 0,
662 DisableLPalShortcuts = 1, DisableCompileConsole = 0, numericalFlags = 0,
663 ActiveLayerHighlight = 0, DragCenterOfSquares = 0;
664 uint8_t InvalidBG = 0;
665 bool NoHighlightLayer0 = false;
666 int32_t FlashWarpSquare = -1, FlashWarpClk = 0; // flash the destination warp return when ShowSquares is active
667 uint8_t ViewLayer3BG = 0, ViewLayer2BG = 0;
668 int32_t window_width, window_height;
669 bool ShowFPS = false, SaveDragResize = false, DragAspect = false, SaveWinPos=false;
670 bool allowHideMouse = false;
671 double aspect_ratio = LARGE_H / double(LARGE_W);
672 int window_min_width = 0, window_min_height = 0;
673 int32_t ComboBrush = 0; //show the brush instead of the normal mouse
674 int32_t ComboBrushPause = 0; //temporarily disable the combo brush
675 int32_t FloatBrush = 0; //makes the combo brush float a few pixels up and left
676 int AutoBrush = 0; //Drag to size the brush on the combo panes
677 bool AutoBrushRevert = false; //Revert after placing
678 int LinkedScroll = 0;
679 //complete with shadow
680 int32_t OpenLastQuest = 0; //makes the program reopen the quest that was
681 //open at the time you quit
682 int32_t ShowMisalignments = 0; //makes the program display arrows over combos that are
683 //not aligned with the next screen.
684 int32_t AnimationOn = 0; //animate the combos in zquest?
685 int32_t AutoBackupRetention = 0; //use auto-backup feature? if so, how many backups (1-10) to keep
686 int32_t AutoSaveInterval = 0; //how often a timed autosave is made (not overwriting the current file)
687 int32_t UncompressedAutoSaves = 0; //should timed saves be uncompressed/encrypted?
688 int32_t KeyboardRepeatDelay = 0; //the time in milliseconds after holding down a key that the key starts to repeat
689 int32_t KeyboardRepeatRate = 0; //the time in milliseconds between each repetition of a repeated key
690
691 time_t auto_save_time_start, auto_save_time_current;
692 double auto_save_time_diff = 0;
693 int32_t AutoSaveRetention = 0; //how many autosaves of a quest to keep
694 int32_t ImportMapBias = 0; //tells what has precedence on map importing
695 int32_t BrushWidth=1, BrushHeight=1;
696 bool saved=true;
697 bool __debug=false;
698 int32_t LayerMaskInt[7]={0};
699 int32_t CurrentLayer=0;
700 int32_t DuplicateAction[4]={0};
701 int32_t OnlyCheckNewTilesForDuplicates = 0;
702 int32_t try_recovering_missing_scripts = 0;
703
704 uint8_t PreFillTileEditorPage = 0, PreFillComboEditorPage = 0;
705 int32_t DMapEditorLastMaptileUsed = 0;
706
707 /*
708 , HorizontalDuplicateAction;
709 int32_t VerticalDuplicateAction, BothDuplicateAction;
710 */
711 word msg_count = 0;
712 int32_t LeechUpdate = 0;
713 int32_t LeechUpdateTiles = 0;
714 int32_t SnapshotFormat = 0;
715 byte SnapshotScale = 0;
716
717 byte Color = 0;
718 extern int32_t jwin_pal[jcMAX];
719 int32_t gui_colorset=99;
720
721 static int32_t combo_apos=0; //currently selected combo alias
722 int32_t alias_origin=0;
723 int32_t alias_cset_mod=0;
724
725 static int32_t combo_pool_pos=0; //currently selected combo pool
726 bool weighted_cpool = true;
727 bool cpool_prev_visible = false;
728
729 static int32_t combo_auto_pos=0; //currently selected autocombo
730 byte cauto_height = 1;
731
732 bool trip=false;
733
734 int32_t fill_type=1;
735
736 bool first_save=false;
737 char *filepath,*midipath,*datapath,*imagepath,*tmusicpath,*last_timed_save;
738 string helpstr, zstringshelpstr;
739
740 ZCMUSIC *zcmusic = NULL;
741 ZCMIXER *zcmixer = NULL;
742 int32_t midi_volume = 255;
743 extern int32_t prv_mode;
744 int32_t prv_warp = 0;
745 int32_t prv_twon = 0;
746 int32_t ff_combo = 0;
747
748 int32_t Frameskip = 0, RequestedFPS = 60, zqUseWin32Proc = 1;
749 int32_t zqColorDepth = 8;
750 int32_t joystick_index=0;
751
752 11 void set_last_timed_save(char const* buf)
753 {
754
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if(buf && buf[0])
755 {
756 if(buf != last_timed_save)
757 strcpy(last_timed_save, buf);
758 }
759 else
760 {
761 11 last_timed_save[0] = 0;
762 11 buf = nullptr;
763 }
764 11 zc_set_config("zquest","last_timed_save",buf);
765 11 }
766
767 void loadlvlpal(int32_t level);
768 bool get_debug()
769 {
770 return __debug;
771 //return true;
772 }
773
774 void set_debug(bool d)
775 {
776 __debug=d;
777 return;
778 }
779
780 bool handle_quit()
781 {
782 if(onExit()==D_CLOSE)
783 return (exiting_program = true);
784 return false;
785 }
786 bool handle_close_btn_quit()
787 {
788 if(close_button_quit)
789 {
790 close_button_quit=false;
791 return handle_quit();
792 }
793 return false;
794 }
795 // **** Timers ****
796
797 volatile int32_t lastfps=0;
798 volatile int32_t framecnt=0;
799 size_t cpoolbrush_index = 0;
800
801 // quest data
802 12 zquestheader header;
803 byte midi_flags[MIDIFLAGS_SIZE];
804 byte music_flags[MUSICFLAGS_SIZE];
805 byte *quest_file;
806 int32_t msg_strings_size;
807 zctune *customtunes;
808 //emusic *enhancedMusic;
809 ZCHEATS zcheats;
810 byte use_cheats;
811 byte use_tiles;
812 // Note: may not be null-terminated (must refactor writecolordata to fix).
813 char palnames[MAXLEVELS][17];
814 char zquestdat_sig[52];
815 char qstdat_str[2048];
816
817 int32_t gme_track=0;
818
819 int32_t dlevel; // just here until gamedata is properly done
820
821 12 bool bad_version(int32_t ver)
822 {
823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(ver < 0x170)
824 return true;
825
826 12 return false;
827 12 }
828
829 // These are for drawing eyeballs correctly in combo_tile.
830 zfix HeroModifiedX()
831 {
832 return gui_mouse_x() - 7;
833 }
834 zfix HeroModifiedY()
835 {
836 return gui_mouse_y() - 7;
837 }
838
839
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_250_menu
840 48 {
841
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onImport_DMaps },
842
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Table", onImport_Combos },
843
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onImport_ComboAlias },
844 };
845
846
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_graphics
847 180 {
848
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onImport_Pals },
849
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
850
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Tileset (&Full)", onImport_Tiles },
851
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Pack", onImport_Tilepack },
852
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "T&ile Pack to...", onImport_Tilepack_To },
853
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
854
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Set (Range)", onImport_Combos },
855
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack (Full, 1:1)", onImport_Combopack },
856
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack to... (Dest)", onImport_Combopack_To },
857
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
858
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Alias Pack", onImport_Comboaliaspack },
859
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo A&lias Pack to...", onImport_Comboaliaspack_To },
860
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
861
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doorsets", onImport_Doorset },
862 };
863
864
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_menu
865 120 {
866
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onImport_Guys },
867
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map", onImport_Map },
868
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onImport_DMaps },
869
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings (.tsv)", onImport_StringsTSV },
870
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "String Table (deprecated)", onImport_Msgs },
871
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
872
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics", &import_graphics },
873
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
874
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2.50 (Broken)", &import_250_menu },
875 };
876
877
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_250_menu
878 60 {
879
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onExport_DMaps },
880
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Table", onExport_Combos },
881
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onExport_ComboAlias },
882
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics Pack", onExport_ZGP },
883 };
884
885
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu zq_help_menu
886 36 {
887
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Editor Help", onHelp },
888
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings Help", onZstringshelp },
889 };
890
891
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_graphics
892 144 {
893
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onExport_Pals },
894
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
895
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Tileset (&Full)", onExport_Tiles },
896
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Pack", onExport_Tilepack },
897
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
898
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Set", onExport_Combos },
899
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack", onExport_Combopack },
900
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
901
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Alias Pack", onExport_Comboaliaspack },
902
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
903
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doorsets", onExport_Doorset },
904 };
905
906
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_menu
907 132 {
908 #ifdef _WIN32
909 { "&Package", onExport_Package },
910 #endif
911
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onExport_Guys },
912
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map", onExport_Map },
913
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onExport_DMaps },
914
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
915
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings (.tsv)", onExport_StringsTSV },
916
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "String Table (deprecated)", onExport_Msgs },
917
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
918
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics", &export_graphics },
919
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
920
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2.50 (Broken)", &export_250_menu },
921 };
922
923
924
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu recent_menu
925 132 {
926
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
927
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
928
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
929
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
930
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
931
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
932
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
933
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
934
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
935
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
936 };
937 static char rec_menu_fullpaths[10][512];
938 static char rec_menu_strs[10][64];
939
940 int32_t customOpen(char const* path);
941 void do_recent_quest(uint32_t ind)
942 {
943 if(ind > 9) return;
944 strcpy(temppath, rec_menu_fullpaths[ind]);
945 customOpen(temppath);
946 }
947 int32_t do_RecentQuest_0() { do_recent_quest(0); return D_O_K; }
948 int32_t do_RecentQuest_1() { do_recent_quest(1); return D_O_K; }
949 int32_t do_RecentQuest_2() { do_recent_quest(2); return D_O_K; }
950 int32_t do_RecentQuest_3() { do_recent_quest(3); return D_O_K; }
951 int32_t do_RecentQuest_4() { do_recent_quest(4); return D_O_K; }
952 int32_t do_RecentQuest_5() { do_recent_quest(5); return D_O_K; }
953 int32_t do_RecentQuest_6() { do_recent_quest(6); return D_O_K; }
954 int32_t do_RecentQuest_7() { do_recent_quest(7); return D_O_K; }
955 int32_t do_RecentQuest_8() { do_recent_quest(8); return D_O_K; }
956 int32_t do_RecentQuest_9() { do_recent_quest(9); return D_O_K; }
957
958 2 void refresh_recent_menu()
959 {
960 2 int32_t (*procs[10])(void) = {
961 do_RecentQuest_0, do_RecentQuest_1, do_RecentQuest_2, do_RecentQuest_3,
962 do_RecentQuest_4, do_RecentQuest_5, do_RecentQuest_6,
963 do_RecentQuest_7, do_RecentQuest_8, do_RecentQuest_9
964 };
965
5/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
2 static MenuItem nilitem("---",nullptr,nullopt,true);
966
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
22 for(auto q = 0; q < 10; ++q)
967 {
968 20 MenuItem& mit = *recent_menu.at(q);
969 20 bool valid = rec_menu_fullpaths[q][0] != '-';
970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(valid)
971 mit = MenuItem(rec_menu_strs[q],procs[q]);
972 20 else mit = nilitem;
973 20 }
974 2 }
975
976 1 void load_recent_quests()
977 {
978 1 char configname[64] = "rec_qst_";
979 1 char* ptr = &configname[strlen(configname)];
980 1 char buf[512] = {0};
981
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for(auto q = 0; q < 10; ++q)
982 {
983 10 sprintf(ptr, "%d", q); //increment the configname value
984 10 char const* qst_str = zc_get_config("recent",configname,nullptr);
985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(qst_str[0])
986 {
987 strncpy(rec_menu_fullpaths[q], qst_str, 511);
988 relativize_path(buf, rec_menu_fullpaths[q]);
989 if(strlen(buf) > 62)
990 {
991 buf[60] = buf[61] = buf[62] = '.'; //add "..." as the last 3 characters
992 }
993 strncpy(rec_menu_strs[q], buf, 63);
994 }
995 else
996 {
997 10 strcpy(rec_menu_fullpaths[q], "---");
998 10 strcpy(rec_menu_strs[q], "---");
999 }
1000 10 rec_menu_fullpaths[q][511] = 0;
1001 10 rec_menu_strs[q][63] = 0;
1002 10 }
1003 1 refresh_recent_menu();
1004 1 }
1005
1006 void write_recent_quests()
1007 {
1008 char configname[64] = "rec_qst_";
1009 char* ptr = &configname[strlen(configname)];
1010 for(auto q = 0; q < 10; ++q)
1011 {
1012 sprintf(ptr, "%d", q); //increment the configname value
1013 zc_set_config("recent",configname,(rec_menu_fullpaths[q][0]!='-') ? rec_menu_fullpaths[q] : nullptr);
1014 }
1015 }
1016
1017 void update_recent_quest(char const* path)
1018 {
1019 int32_t ind = -1;
1020 for(auto q = 0; q < 10; ++q)
1021 {
1022 if(!strcmp(path, rec_menu_fullpaths[q]))
1023 {
1024 ind = q;
1025 break;
1026 }
1027 }
1028 if(ind > -1)
1029 {
1030 for(auto q = ind; q > 0; --q)
1031 {
1032 strcpy(rec_menu_fullpaths[q], rec_menu_fullpaths[q-1]);
1033 strcpy(rec_menu_strs[q], rec_menu_strs[q-1]);
1034 }
1035 }
1036 else
1037 {
1038 int32_t free_ind = 9; //if none found, override the last index
1039 for(auto q = 0; q < 9; ++q)
1040 {
1041 if(rec_menu_fullpaths[q][0] == '-')
1042 {
1043 free_ind = q;
1044 break;
1045 }
1046 }
1047
1048 for(auto q = free_ind; q > 0; --q)
1049 {
1050 strcpy(rec_menu_fullpaths[q], rec_menu_fullpaths[q-1]);
1051 strcpy(rec_menu_strs[q], rec_menu_strs[q-1]);
1052 }
1053 }
1054 char buf[512] = {0};
1055 strcpy(rec_menu_fullpaths[0], path);
1056 relativize_path(buf, rec_menu_fullpaths[0]);
1057 if(strlen(buf) > 62)
1058 {
1059 buf[60] = buf[61] = buf[62] = '.'; //add "..." as the last 3 characters
1060 }
1061 strncpy(rec_menu_strs[0], buf, 63);
1062 refresh_recent_menu();
1063 zc_set_config("zquest",last_quest_name,path);
1064 write_recent_quests();
1065 }
1066
1067 void reload_zq_gui()
1068 {
1069 init_custom_fonts();
1070 load_size_poses();
1071 refresh_visible_screens();
1072 update_combobrush();
1073 refresh(rCLEAR|rALL);
1074 }
1075 void change_mapscr_zoom(int delta)
1076 {
1077 int num_screens = Map.getViewSize();
1078 num_screens = std::clamp(num_screens + delta, 1, mapscreen_num_screens_to_draw_max);
1079 Map.setViewSize(num_screens);
1080 std::string qst_cfg_header = qst_cfg_header_from_path(filepath);
1081 zc_set_config(qst_cfg_header.c_str(), "zoom_num_screens", Map.getViewSize());
1082 reload_zq_gui();
1083 }
1084 void toggle_is_compact()
1085 {
1086 is_compact = !is_compact;
1087 zc_set_config("ZQ_GUI","compact_mode",is_compact?1:0);
1088 reload_zq_gui();
1089 }
1090 void toggle_merged_mode()
1091 {
1092 if(is_compact)
1093 {
1094 compact_merged_combopane = !compact_merged_combopane;
1095 zc_set_config("ZQ_GUI","merge_cpane_compact",compact_merged_combopane?1:0);
1096 }
1097 else
1098 {
1099 large_merged_combopane = !large_merged_combopane;
1100 zc_set_config("ZQ_GUI","merge_cpane_large",large_merged_combopane?1:0);
1101 }
1102 reload_zq_gui();
1103 }
1104 void toggle_compact_sqr_mode()
1105 {
1106 compact_square_panels = !compact_square_panels;
1107 zc_set_config("ZQ_GUI","square_panels_compact",compact_square_panels?1:0);
1108 reload_zq_gui();
1109 }
1110 void cycle_compact_sqr(bool down)
1111 {
1112 if(!(is_compact && compact_square_panels))
1113 return;
1114 static const int num_panels = 3;
1115 if(down)
1116 compact_active_panel = (compact_active_panel+1)%num_panels;
1117 else
1118 compact_active_panel = (compact_active_panel-1+num_panels)%num_panels;
1119 reload_zq_gui();
1120 }
1121 void toggle_favzoom_mode()
1122 {
1123 if(is_compact)
1124 {
1125 compact_zoomed_fav = !compact_zoomed_fav;
1126 zc_set_config("ZQ_GUI","zoom_fav_compact",compact_zoomed_fav?1:0);
1127 }
1128 else
1129 {
1130 large_zoomed_fav = !large_zoomed_fav;
1131 zc_set_config("ZQ_GUI","zoom_fav_large",large_zoomed_fav?1:0);
1132 }
1133 reload_zq_gui();
1134 }
1135 void toggle_cmdzoom_mode()
1136 {
1137 if(is_compact)
1138 {
1139 compact_zoomed_cmd = !compact_zoomed_cmd;
1140 zc_set_config("ZQ_GUI","zoom_cmd_compact",compact_zoomed_cmd?1:0);
1141 }
1142 else
1143 {
1144 large_zoomed_cmd = !large_zoomed_cmd;
1145 zc_set_config("ZQ_GUI","zoom_cmd_large",large_zoomed_cmd?1:0);
1146 }
1147 reload_zq_gui();
1148 }
1149
1150 enum
1151 {
1152 MENUID_FILE_SAVE,
1153 MENUID_FILE_SAVEAS,
1154 MENUID_FILE_REVERT,
1155 };
1156
1157
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu file_menu
1158 156 {
1159
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&New", do_NewQuest },
1160
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Open", do_OpenQuest },
1161
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Recent", &recent_menu },
1162
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1163
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Save", onSave, MENUID_FILE_SAVE },
1164
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Save &as...", onSaveAs, MENUID_FILE_SAVEAS },
1165
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Revert", onRevert, MENUID_FILE_REVERT },
1166
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1167
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Import", &import_menu },
1168
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Export", &export_menu },
1169 #ifndef __EMSCRIPTEN__
1170
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1171
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "E&xit", handle_quit },
1172 #endif
1173 };
1174
1175 enum
1176 {
1177 MENUID_MAPS_NEXT,
1178 MENUID_MAPS_PREV,
1179 };
1180
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu maps_menu
1181 72 {
1182
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Goto Map...", onGotoMap },
1183
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Next Map", onIncMap, MENUID_MAPS_NEXT },
1184
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Previous Map", onDecMap, MENUID_MAPS_PREV },
1185
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1186
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "D&elete Map", onDeleteMap },
1187 };
1188
1189
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu misc_menu
1190 120 {
1191
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "S&ubscreens", onEditSubscreens },
1192
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Shop Types", onShopTypes },
1193
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Bottle Types", onBottleTypes },
1194
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Bottle S&hop Types", onBottleShopTypes },
1195
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Info Types", onInfoTypes },
1196
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warp Rings", onWarpRings },
1197
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Triforce Pieces", onTriPieces },
1198
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&End String", onEndString },
1199
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Item &Drop Sets", onItemDropSets },
1200 };
1201
1202
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu spr_menu
1203 48 {
1204
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprite Data", onCustomWpns },
1205
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hero", onCustomHero },
1206
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Misc Sprites", onMiscSprites },
1207 };
1208
1209
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 NewMenu colors_menu
1210 48 {
1211
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Main ", onColors_Main },
1212
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Levels ", onColors_Levels },
1213
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprites ", onColors_Sprites },
1214 };
1215
1216
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu defs_menu
1217 108 {
1218
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onDefault_Pals },
1219
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tiles", onDefault_Tiles },
1220
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combos", onDefault_Combos },
1221
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Items", onDefault_Items },
1222
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onDefault_Guys },
1223
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprite Data", onDefault_Weapons },
1224
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map Styles", onDefault_MapStyles },
1225
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "SF&X Data", onDefault_SFX },
1226 };
1227
1228 int32_t onEditComboAlias();
1229 int32_t onEditComboPool();
1230 int32_t onEditAutoCombo();
1231
1232
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu graphics_menu
1233 120 {
1234
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes ", &colors_menu },
1235
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprites ", &spr_menu },
1236
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combos", onCombos },
1237
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tiles", onTiles },
1238
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Game icons", onIcons },
1239
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Misc co&lors", onMiscColors },
1240
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map styles", onMapStyles },
1241
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Door Combo Sets", onDoorCombos },
1242
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Aliases", onEditComboAlias },
1243 };
1244
1245
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu audio_menu
1246 48 {
1247
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "SF&X Data", onSelectSFX },
1248
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&MIDIs", onMidis },
1249
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Mis&c SFX", onMiscSFX },
1250 };
1251
1252 void set_rules(byte* newrules);
1253
1254 void call_testqst_dialog();
1255 int32_t onTestQst()
1256 {
1257 call_testqst_dialog();
1258 return D_O_K;
1259 }
1260
1261 int32_t onRulesDlg()
1262 {
1263 call_qr_dialog(21, set_rules);
1264 return D_O_K;
1265 }
1266
1267 int32_t onRulesSearch()
1268 {
1269 call_qrsearch_dialog(set_rules);
1270 return D_O_K;
1271 }
1272
1273 int32_t onZScriptSettings()
1274 {
1275 ScriptRulesDialog(quest_rules, 17, [](byte* newrules)
1276 {
1277 saved = false;
1278 memcpy(quest_rules, newrules, QR_SZ);
1279 unpack_qrs();
1280 }).show();
1281 return D_O_K;
1282 }
1283
1284 void call_zinf_dlg();
1285 int32_t onZInfo()
1286 {
1287 call_zinf_dlg();
1288 return D_O_K;
1289 }
1290
1291
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu quest_menu
1292 204 {
1293
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Options ", onRulesDlg },
1294
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Test", onTestQst },
1295
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Items", onCustomItems },
1296
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onCustomEnemies },
1297
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hero", onCustomHero },
1298
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings", onStrings },
1299
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onDmaps },
1300
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map Settings", onMaps },
1301
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "I&nit Data", onInit },
1302
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Misc D&ata ", &misc_menu },
1303
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&ZInfo", onZInfo },
1304
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1305
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics ", &graphics_menu },
1306
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "A&udio ", &audio_menu },
1307
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1308
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "De&faults ", &defs_menu },
1309 };
1310
1311
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_menu
1312 36 {
1313
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &To All", onPasteToAll },
1314
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &All To All", onPasteAllToAll },
1315 };
1316
1317
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_item_menu
1318 156 {
1319
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Undercombo", onPasteUnderCombo },
1320
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Secret Combos", onPasteSecretCombos },
1321
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Freeform Combos", onPasteFFCombos },
1322
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Screen &Data", onPasteScreenData },
1323
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warps", onPasteWarps },
1324
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Warp &Return", onPasteWarpLocations },
1325
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onPasteEnemies },
1326
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Room &Type Data", onPasteRoom },
1327
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Guy/String", onPasteGuy },
1328
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Doo&rs", onPasteDoors },
1329
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Layers", onPasteLayers },
1330
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palette", onPastePalette },
1331 };
1332
1333 enum
1334 {
1335 MENUID_EDIT_UNDO,
1336 MENUID_EDIT_REDO,
1337 MENUID_EDIT_COPY,
1338 MENUID_EDIT_PASTE,
1339 MENUID_EDIT_PASTEALL,
1340 MENUID_EDIT_ADVPASTE,
1341 MENUID_EDIT_SPECPASTE,
1342 MENUID_EDIT_DELETE,
1343 };
1344
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu edit_menu
1345 132 {
1346
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Undo", onUndo, MENUID_EDIT_UNDO },
1347
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Redo", onRedo, MENUID_EDIT_REDO },
1348
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Copy", onCopy, MENUID_EDIT_COPY },
1349
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Paste", onPaste, MENUID_EDIT_PASTE },
1350
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste A&ll", onPasteAll, MENUID_EDIT_PASTEALL },
1351
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Adv. Paste ", &paste_menu, MENUID_EDIT_ADVPASTE },
1352
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &Spec. ", &paste_item_menu, MENUID_EDIT_SPECPASTE },
1353
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Delete", onDelete, MENUID_EDIT_DELETE },
1354
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1355
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Maps ", &maps_menu },
1356 };
1357
1358
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu drawing_mode_menu
1359 60 {
1360
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Normal", onDrawingModeNormal, dm_normal },
1361
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onDrawingModeAlias, dm_alias },
1362
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Pool", onDrawingModePool, dm_cpool },
1363
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Auto Combo", onDrawingModeAuto, dm_auto },
1364 };
1365
1366
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu integrity_check_menu
1367 48 {
1368
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&All ", onIntegrityCheckAll },
1369
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screens ", onIntegrityCheckRooms },
1370
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warps ", onIntegrityCheckWarps },
1371 };
1372
1373
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu quest_reports_menu
1374 108 {
1375
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Bugged Next-> Combo Locations", onBuggedNextComboLocationReport },
1376
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Locations", onComboLocationReport },
1377
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Type Locations", onComboTypeLocationReport },
1378
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemy Locations", onEnemyLocationReport },
1379
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Item Locations", onItemLocationReport },
1380
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Script Locations", onScriptLocationReport },
1381
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&What Links Here", onWhatWarpsReport },
1382
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "In&tegrity Check ", &integrity_check_menu },
1383 };
1384
1385 int32_t onPalFix();
1386 int32_t onPitFix();
1387 int32_t onStrFix()
1388 {
1389 if(get_qr(qr_OLD_STRING_EDITOR_MARGINS))
1390 {
1391 AlertDialog("Fix: Old Margins",
1392 "Fixing margins may cause strings that used to spill outside the textbox"
1393 " to instead be cut off. Are you sure?",
1394 [&](bool ret,bool)
1395 {
1396 if(ret)
1397 {
1398 set_qr(qr_OLD_STRING_EDITOR_MARGINS, 0);
1399 saved = false;
1400 }
1401 }).show();
1402 }
1403 if(get_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT))
1404 {
1405 AlertDialog("Fix: Old Frame Size",
1406 "This will fix the frame size of all strings. No visual changes should occur,"
1407 " as the string width/height will be fixed, but the compat QR will also be unchecked.",
1408 [&](bool ret,bool)
1409 {
1410 if(ret)
1411 {
1412 for(auto q = 0; q < msg_count; ++q)
1413 {
1414 MsgStrings[q].w += 16;
1415 MsgStrings[q].h += 16;
1416 }
1417 set_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT, 0);
1418 saved = false;
1419 }
1420 }).show();
1421 }
1422 return D_O_K;
1423 }
1424
1425 int32_t onRemoveOldArrivalSquare();
1426 enum
1427 {
1428 MENUID_FIXTOOL_OLDSTRING,
1429 };
1430
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu fixtools_menu
1431 96 {
1432
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Color Set Fix", onCSetFix },
1433
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Liquid Solidity Fix", onWaterSolidity },
1434
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Effect Square Fix", onEffectFix },
1435
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Level Palette Fix", onPalFix },
1436
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Pit and Liquid Damage Fix", onPitFix },
1437
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Old Strings Fix", onStrFix, MENUID_FIXTOOL_OLDSTRING },
1438
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Green Arrival Square Fix", onRemoveOldArrivalSquare },
1439 };
1440
1441
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu tool_menu
1442 132 {
1443
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Flags", onFlags, nullopt, MFL_EXIT_PRE_PROC },
1444
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fix &Tools ", &fixtools_menu },
1445
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&NES Dungeon Template", onTemplate },
1446
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Apply Template to All", onReTemplate },
1447
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1448
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Preview Mode", onPreviewMode },
1449
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Drawing &Mode ", &drawing_mode_menu },
1450
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1451
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&List Combos Used", onUsedCombos },
1452
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest Reports ", &quest_reports_menu },
1453 };
1454
1455 int32_t onLayer3BG()
1456 {
1457 ViewLayer3BG = ViewLayer3BG ? 0 : 1;
1458 zc_set_config("zquest","layer3_bg",ViewLayer3BG);
1459 return D_O_K;
1460 }
1461 int32_t onLayer2BG()
1462 {
1463 ViewLayer2BG = ViewLayer2BG ? 0 : 1;
1464 zc_set_config("zquest","layer2_bg",ViewLayer2BG);
1465 return D_O_K;
1466 }
1467 int onGridToggle();
1468 enum
1469 {
1470 MENUID_VIEW_WALKABILITY,
1471 MENUID_VIEW_FLAGS,
1472 MENUID_VIEW_CSET,
1473 MENUID_VIEW_TYPES,
1474 MENUID_VIEW_INFO,
1475 MENUID_VIEW_SQUARES,
1476 MENUID_VIEW_FFCS,
1477 MENUID_VIEW_SCRIPTNAMES,
1478 MENUID_VIEW_GRID,
1479 MENUID_VIEW_SCREENGRID,
1480 MENUID_VIEW_REGIONGRID,
1481 MENUID_VIEW_CURSCROUTLINE,
1482 MENUID_VIEW_DARKNESS,
1483 MENUID_VIEW_L2BG,
1484 MENUID_VIEW_L3BG,
1485 MENUID_VIEW_LAYERHIGHLIGHT,
1486 };
1487
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 NewMenu view_menu
1488 252 {
1489
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "View &Map...", onViewMap },
1490
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "View &Palette", onShowPal },
1491
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1492
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Walkability", onShowWalkability, MENUID_VIEW_WALKABILITY },
1493
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Flags", onShowFlags, MENUID_VIEW_FLAGS },
1494
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &CSets", onShowCSet, MENUID_VIEW_CSET },
1495
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Types", onShowCType, MENUID_VIEW_TYPES },
1496
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1497
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Screen &Info", onToggleShowInfo, MENUID_VIEW_INFO },
1498
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Squares", onToggleShowSquares, MENUID_VIEW_SQUARES },
1499
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show FFCs", onToggleShowFFCs, MENUID_VIEW_FFCS },
1500
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Script &Names", onToggleShowScripts, MENUID_VIEW_SCRIPTNAMES },
1501
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Grid", onGridToggle, MENUID_VIEW_GRID },
1502
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Screen G&rid", onToggleScreenGrid, MENUID_VIEW_SCREENGRID },
1503
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Region Grid", onToggleRegionGrid, MENUID_VIEW_REGIONGRID },
1504
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Current Screen Outline", onToggleCurrentScreenOutline, MENUID_VIEW_CURSCROUTLINE },
1505
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Darkness", onShowDarkness, MENUID_VIEW_DARKNESS },
1506
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Layer 2 is Background", onLayer2BG, MENUID_VIEW_L2BG },
1507
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Layer 3 is Background", onLayer3BG, MENUID_VIEW_L3BG },
1508
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Highlight Current Layer", onToggleHighlightLayer, MENUID_VIEW_LAYERHIGHLIGHT },
1509 };
1510
1511 11 void set_rules(byte* newrules)
1512 {
1513 11 saved = false;
1514
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(newrules != quest_rules)
1515 memcpy(quest_rules, newrules, QR_SZ);
1516 11 unpack_qrs();
1517
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 if(!get_qr(qr_ALLOW_EDITING_COMBO_0))
1518 {
1519 2 combobuf[0].walk = 0xF0;
1520 2 combobuf[0].type = 0;
1521 2 combobuf[0].flag = 0;
1522 2 }
1523
1524 // For 2.50.0 and 2.50.1
1525
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 if(get_qr(qr_VERYFASTSCROLLING))
1526 2 set_qr(qr_FASTDNGN, 1);
1527 11 }
1528
1529 int32_t onSelectFFCombo();
1530
1531 void onScreenNotes()
1532 {
1533 edit_screen_notes(Map.CurrScr(), Map.getCurrMap(), Map.getCurrScr());
1534 }
1535
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu data_menu
1536 216 {
1537
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screen Data", onScrData },
1538
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Freeform Combos", onSelectFFCombo },
1539
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "La&yers", onLayers },
1540
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Warp", onTileWarp },
1541
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Side &Warp", onSideWarp },
1542
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Secret &Combos", onSecretCombo },
1543
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Under Combo", onUnderCombo },
1544
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doors", onDoors },
1545
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Maze Path", onPath },
1546
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1547
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Item", onItem },
1548
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onEnemies },
1549
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palette", onScreenPalette },
1550
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1551
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Room Data", onRoom },
1552
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Notes", onScreenNotes },
1553
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Browse Notes", browse_screen_notes },
1554 };
1555
1556
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu tunes_menu
1557 252 {
1558
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "ZC Forever", playZCForever },
1559
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Wind Fish", playTune1 },
1560
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Overworld", playTune2 },
1561
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Hyrule Castle", playTune3 },
1562
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Lost Woods", playTune4 },
1563
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Great Sea", playTune5 },
1564
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "East Hyrule", playTune6 },
1565
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dancing Dragon", playTune7 },
1566
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Stone Tower", playTune8 },
1567
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Villages", playTune9 },
1568
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Swamp + Desert", playTune10 },
1569
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Outset Island", playTune11 },
1570
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Kakariko Village", playTune12 },
1571
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Clock Town", playTune13 },
1572
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Temple", playTune14 },
1573
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dark World", playTune15 },
1574
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dragon Roost", playTune16 },
1575
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Horse Race", playTune17 },
1576
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Credits", playTune18 },
1577
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Zelda's Lullaby", playTune19 },
1578 };
1579
1580 enum
1581 {
1582 MENUID_MEDIA_TUNES,
1583 MENUID_MEDIA_PLAYMUSIC,
1584 MENUID_MEDIA_CHANGETRACK,
1585 };
1586
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu media_menu
1587 60 {
1588
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Ambient Music ", &tunes_menu, MENUID_MEDIA_TUNES },
1589
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Play music", playMusic, MENUID_MEDIA_PLAYMUSIC },
1590
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Change track", changeTrack, MENUID_MEDIA_CHANGETRACK },
1591
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Stop tunes", stopMusic },
1592 };
1593
1594 enum
1595 {
1596 MENUID_ETC_VIDMODE,
1597 MENUID_ETC_FULLSCREEN,
1598 MENUID_ETC_DEBUG_CONSOLE,
1599 };
1600
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu etc_menu
1601 192 {
1602
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Help", &zq_help_menu },
1603
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&About", onAbout },
1604
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Video Mode", onZQVidMode, MENUID_ETC_VIDMODE },
1605
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Options...", onOptions },
1606
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hotkeys...", do_zq_hotkey_dialog },
1607
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&List Hotkeys...", do_zq_list_hotkeys_dialog },
1608
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Fullscreen", onFullScreen, MENUID_ETC_FULLSCREEN },
1609
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1610
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&View Pic...", onViewPic },
1611
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Media", &media_menu },
1612
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1613
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Debug Console", toggleConsole, MENUID_ETC_DEBUG_CONSOLE },
1614
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Clear Quest Filepath", onClearQuestFilepath },
1615
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Take ZQ Snapshot", onMenuSnapshot },
1616
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Take &Screen Snapshot", onMapscrSnapshot },
1617 };
1618
1619
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu zscript_menu
1620 60 {
1621
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Compile &ZScript...", onCompileScript },
1622
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1623
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Compiler Settings", onZScriptCompilerSettings },
1624
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest Script Settings", onZScriptSettings },
1625 };
1626
1627 void set_console_state()
1628 {
1629 etc_menu.select_uid(MENUID_ETC_DEBUG_CONSOLE, console_is_open);
1630 }
1631
1632
3/16
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
12 NewMenu foo_menu{{"FOO",[](){InfoDialog("PLACEHOLDER","THIS IS A PLACEHOLDER").show();}}};
1633
1634
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 TopMenu the_menu
1635 108 {
1636
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&File", &file_menu },
1637
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest", &quest_menu },
1638
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Edit", &edit_menu },
1639
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&View", &view_menu },
1640
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tools", &tool_menu },
1641
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screen", &data_menu },
1642
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&ZScript", &zscript_menu },
1643
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Et&C", &etc_menu },
1644 };
1645
1646 void rebuild_trans_table();
1647 int32_t launchPicViewer(BITMAP **pictoview, PALETTE pal,
1648 int32_t *px2, int32_t *py2, double *scale, bool isviewingmap, bool skipmenu = false);
1649
1650 int32_t onResetTransparency()
1651 {
1652 restore_mouse();
1653 rebuild_trans_table();
1654 jwin_alert("Notice","Translucency Table Rebuilt",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
1655
1656 refresh(rALL);
1657 return D_O_K;
1658 }
1659
1660 int32_t onFullScreen()
1661 {
1662 get_palette(RAMpal);
1663 bool windowed=is_windowed_mode()!=0;
1664 all_toggle_fullscreen(windowed);
1665
1666 gui_mouse_focus=0;
1667 gui_bg_color=jwin_pal[jcBOX];
1668 gui_fg_color=jwin_pal[jcBOXFG];
1669 MouseSprite::set(ZQM_NORMAL);
1670 zc_set_palette(RAMpal);
1671 position_mouse(zq_screen_w/2,zq_screen_h/2);
1672 set_display_switch_mode(SWITCH_BACKGROUND);
1673 set_display_switch_callback(SWITCH_OUT, switch_out);
1674 set_display_switch_callback(SWITCH_IN, switch_in);
1675 zc_set_config("zquest","fullscreen", is_windowed_mode() ? 0 : 1);
1676 return D_REDRAW;
1677 }
1678
1679 int32_t onEnter()
1680 {
1681 if(key[KEY_ALT]||key[KEY_ALTGR])
1682 {
1683 return onFullScreen();
1684 }
1685
1686 return D_O_K;
1687 }
1688
1689 //PROC, x, y, w, h, fg, bg, key, flags, d1, d2, *dp, *dp2, *dp3
1690
1691 //*text, (*proc), *child, flags, *dp
1692
1693 void run_zq_frame();
1694 int32_t d_nbmenu_proc(int32_t msg,DIALOG *d,int32_t c);
1695
1696
1697 /*int32_t onY()
1698 {
1699 return D_O_K;
1700 }*/
1701
1702 int32_t onToggleGrid(bool color)
1703 {
1704 if(color)
1705 {
1706 GridColor=(GridColor+8)%16;
1707 zc_set_config("zquest", "grid_color", GridColor);
1708 }
1709 else
1710 {
1711 ShowGrid=!ShowGrid;
1712 zc_set_config("zquest","show_grid",ShowGrid);
1713 }
1714
1715 return D_O_K;
1716 }
1717
1718 int onGridToggle()
1719 {
1720 return onToggleGrid(CHECK_CTRL_CMD);
1721 }
1722
1723 int32_t onToggleScreenGrid()
1724 {
1725 ShowScreenGrid=!ShowScreenGrid;
1726 zc_set_config("zquest","show_screen_grid",ShowScreenGrid);
1727 return D_O_K;
1728 }
1729
1730 int32_t onToggleRegionGrid()
1731 {
1732 ShowRegionGrid=!ShowRegionGrid;
1733 zc_set_config("zquest","show_region_grid",ShowRegionGrid);
1734 return D_O_K;
1735 }
1736
1737 int32_t onToggleCurrentScreenOutline()
1738 {
1739 ShowCurScreenOutline=!ShowCurScreenOutline;
1740 zc_set_config("zquest","show_current_screen_outline",ShowCurScreenOutline);
1741 return D_O_K;
1742 }
1743
1744 int32_t onToggleShowScripts()
1745 {
1746 ShowFFScripts=!ShowFFScripts;
1747 zc_set_config("zquest","showffscripts",ShowFFScripts);
1748 return D_O_K;
1749 }
1750
1751 int32_t onToggleShowFFCs()
1752 {
1753 ShowFFCs=!ShowFFCs;
1754 zc_set_config("zquest","showffcs",ShowFFCs);
1755 return D_O_K;
1756 }
1757
1758 int32_t onToggleShowSquares()
1759 {
1760 ShowSquares=!ShowSquares;
1761 zc_set_config("zquest","showsquares",ShowSquares);
1762 return D_O_K;
1763 }
1764
1765 int32_t onToggleShowInfo()
1766 {
1767 ShowInfo=!ShowInfo;
1768 zc_set_config("zquest","showinfo",ShowInfo);
1769 return D_O_K;
1770 }
1771
1772 int32_t onToggleHighlightLayer()
1773 {
1774 ActiveLayerHighlight = ActiveLayerHighlight ? 0 : 1;
1775 zc_set_config("zquest","hl_active_lyr",ActiveLayerHighlight);
1776 return D_O_K;
1777 }
1778
1779 int onKeySlash()
1780 {
1781 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
1782 {
1783 onAbout();
1784 }
1785 return D_O_K;
1786 }
1787
1788 int onAKey()
1789 {
1790 if(prv_mode)
1791 Map.set_prvadvance(1);
1792 return D_O_K;
1793 }
1794
1795 int onReloadPreview()
1796 {
1797 if(prv_mode)
1798 {
1799 Map.set_prvscr(Map.get_prv_map(), Map.get_prv_scr());
1800 Map.set_prvcmb(0);
1801 }
1802 return D_O_K;
1803 }
1804 int onSecretsPreview()
1805 {
1806 if(prv_mode)
1807 {
1808 Map.prv_secrets(false);
1809 refresh(rALL);
1810 }
1811 return D_O_K;
1812 }
1813
1814 int onSKey()
1815 {
1816 if(CHECK_CTRL_CMD)
1817 {
1818 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
1819 {
1820 onSaveAs();
1821 }
1822 else
1823 {
1824 if(!saved)
1825 onSave();
1826 }
1827 }
1828 else if(prv_mode)
1829 {
1830 Map.prv_secrets(false);
1831 refresh(rALL);
1832 }
1833 else onStrings();
1834 return D_O_K;
1835 }
1836 int onSetNewLayer(int newlayer)
1837 {
1838 CurrentLayer = newlayer;
1839 refresh(rALL);
1840 return D_O_K;
1841 }
1842 void lpal_dsa()
1843 {
1844 info_dsa("Level Palette Shortcuts",
1845 "You currently have level palette shortcuts disabled."
1846 " These can be re-enabled in 'Etc->Options', on the toggle 'Disable Level Palette Shortcuts'.",
1847 "dsa_lpal");
1848 }
1849 int onScreenLPal(int lpal)
1850 {
1851 if(DisableLPalShortcuts)
1852 {
1853 lpal_dsa();
1854 return D_O_K;
1855 }
1856 saved=false;
1857 Map.setcolor(lpal);
1858 refresh(rSCRMAP);
1859 return D_O_K;
1860 }
1861
1862 int32_t onPressEsc()
1863 {
1864 if(zoomed_minimap)
1865 mmap_set_zoom(false);
1866 else return onExit();
1867 return D_O_K;
1868 }
1869
1870 static DIALOG dialogs[] =
1871 {
1872 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
1873 { d_nbmenu_proc, 0, 0, 0, 13, 0, 0, 0, D_USER, 0, 0, (void *) &the_menu, NULL, NULL },
1874 { d_zq_hotkey_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1875
1876 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
1877 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_ESC, 0, (void *) onPressEsc, NULL, NULL },
1878 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, (void *) onUsedCombos, NULL, NULL },
1879 { d_vsync_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1880 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1881 };
1882
1883
1884 int32_t onDecColour()
1885 {
1886 if ( CHECK_CTRL_CMD )
1887 {
1888 return onDecScrPal16();
1889 }
1890
1891 else if ( key[KEY_LSHIFT] || key[KEY_RSHIFT] )
1892 {
1893 return onDecScrPal();
1894 }
1895
1896 else
1897 {
1898 return onDecreaseCSet();
1899 }
1900 }
1901
1902 int32_t onIncColour()
1903 {
1904
1905 if ( CHECK_CTRL_CMD )
1906 {
1907 return onIncScrPal16();
1908 }
1909
1910 else if ( key[KEY_LSHIFT] || key[KEY_RSHIFT] )
1911 {
1912 return onIncScrPal();
1913 }
1914
1915 else
1916 {
1917 return onIncreaseCSet();
1918 }
1919 }
1920
1921 static DIALOG getnum_dlg[] =
1922 {
1923 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
1924 12 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
1925 12 { jwin_rtext_proc, 114, 104+4, 48, 8, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, (void *) "Value:", NULL, NULL },
1926 12 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
1927 12 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
1928 12 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
1929 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1930 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1931 };
1932
1933 int32_t getnumber(const char *prompt,int32_t initialval)
1934 {
1935 cancelgetnum=true;
1936 char buf[20];
1937 sprintf(buf,"%d",initialval);
1938 getnum_dlg[0].dp=(void *)prompt;
1939 getnum_dlg[0].dp2=get_zc_font(font_lfont);
1940 getnum_dlg[2].dp=(void *)buf;
1941
1942 large_dialog(getnum_dlg);
1943
1944 int32_t ret=do_zqdialog(getnum_dlg,2);
1945
1946 if(ret!=0&&ret!=4)
1947 {
1948 cancelgetnum=false;
1949 }
1950
1951 if(ret==3)
1952 return atoi(buf);
1953
1954 return initialval;
1955 }
1956
1957 static DIALOG save_tiles_dlg[] =
1958 {
1959 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
1960
1961
1962 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Tile Pack", NULL, NULL },
1963 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1964 //for future tabs
1965 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1966 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1967 //4
1968 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
1969 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1970 //6
1971 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
1972 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1973 //8
1974 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
1975 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
1976 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1977 };
1978
1979
1980 void savesometiles(const char *prompt,int32_t initialval)
1981 {
1982
1983 char firsttile[8], tilecount[8];
1984 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
1985 sprintf(firsttile,"%d",0);
1986 sprintf(tilecount,"%d",1);
1987 //int32_t ret;
1988
1989
1990
1991 save_tiles_dlg[0].dp2 = get_zc_font(font_lfont);
1992
1993 sprintf(firsttile,"%d",0);
1994 sprintf(tilecount,"%d",1);
1995
1996 save_tiles_dlg[5].dp = firsttile;
1997 save_tiles_dlg[7].dp = tilecount;
1998
1999 large_dialog(save_tiles_dlg);
2000
2001 int32_t ret = do_zqdialog(save_tiles_dlg,-1);
2002 jwin_center_dialog(save_tiles_dlg);
2003
2004 if(ret == 8)
2005 {
2006 first_tile_id = vbound(atoi(firsttile), 0, NEWMAXTILES);
2007 the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2008 if(prompt_for_new_file_compat("Save ZTILE(.ztile)", "ztile", NULL,datapath,false))
2009 {
2010 char name[PATH_MAX];
2011 extract_name(temppath,name,FILENAMEALL);
2012 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2013 if(f)
2014 {
2015 writetilefile(f,first_tile_id,the_tile_count);
2016 pack_fclose(f);
2017 char tmpbuf[PATH_MAX+20]={0};
2018 sprintf(tmpbuf,"Saved %s",name);
2019 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2020 }
2021 }
2022 }
2023 }
2024
2025 static DIALOG read_tiles_dlg[] =
2026 {
2027 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2028
2029
2030 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Tilepack To:", NULL, NULL },
2031 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2032 //for future tabs
2033 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2034 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2035 //4
2036 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2037 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2038 //6
2039 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2040 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2041 //8
2042 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2043 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2044 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2045 };
2046
2047
2048 void writesometiles_to(const char *prompt,int32_t initialval)
2049 {
2050
2051 char firsttile[8];;
2052 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2053 sprintf(firsttile,"%d",0);
2054 //int32_t ret;
2055
2056
2057
2058 read_tiles_dlg[0].dp2 = get_zc_font(font_lfont);
2059
2060 sprintf(firsttile,"%d",0);
2061 //sprintf(tilecount,"%d",1);
2062
2063 read_tiles_dlg[5].dp = firsttile;
2064
2065 large_dialog(read_tiles_dlg);
2066
2067 int32_t ret = do_zqdialog(read_tiles_dlg,-1);
2068 jwin_center_dialog(read_tiles_dlg);
2069
2070 if(ret == 8)
2071 {
2072 first_tile_id = vbound(atoi(firsttile), 0, NEWMAXTILES);
2073 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2074 if(prompt_for_existing_file_compat("Load ZTILE(.ztile)", "ztile", NULL,datapath,false))
2075 {
2076
2077 char name[256];
2078 extract_name(temppath,name,FILENAMEALL);
2079 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2080 if(f)
2081 {
2082
2083 if (!readtilefile_to_location(f,first_tile_id))
2084 {
2085 al_trace("Could not read from .ztile packfile %s\n", name);
2086 jwin_alert("ZTILE File: Error","Could not load the specified Tile.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2087 }
2088 else
2089 {
2090 jwin_alert("ZTILE File: Success!","Loaded the source tiles to your tile sheets!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2091 }
2092 pack_fclose(f);
2093 }
2094 }
2095 }
2096 }
2097
2098
2099 static DIALOG save_combofiles_dlg[] =
2100 {
2101 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2102
2103
2104 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Combo Pack", NULL, NULL },
2105 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2106 //for future tabs
2107 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2108 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2109 //4
2110 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2111 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2112 //6
2113 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2114 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2115 //8
2116 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2117 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2118 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2119 };
2120
2121
2122 void savesomecombos(const char *prompt,int32_t initialval)
2123 {
2124
2125 char firsttile[8], tilecount[8];
2126 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2127 sprintf(firsttile,"%d",0);
2128 sprintf(tilecount,"%d",1);
2129 //int32_t ret;
2130
2131
2132
2133 save_combofiles_dlg[0].dp2 = get_zc_font(font_lfont);
2134
2135 sprintf(firsttile,"%d",0);
2136 sprintf(tilecount,"%d",1);
2137
2138 save_combofiles_dlg[5].dp = firsttile;
2139 save_combofiles_dlg[7].dp = tilecount;
2140
2141 large_dialog(save_combofiles_dlg);
2142
2143 int32_t ret = do_zqdialog(save_combofiles_dlg,-1);
2144 jwin_center_dialog(save_combofiles_dlg);
2145
2146 if(ret == 8)
2147 {
2148 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2149 the_tile_count = vbound(atoi(tilecount), 1, (MAXCOMBOS-1)-first_tile_id);
2150 if(prompt_for_new_file_compat("Save ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2151 {
2152 char name[PATH_MAX];
2153 extract_name(temppath,name,FILENAMEALL);
2154 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2155 if(f)
2156 {
2157 writecombofile(f,first_tile_id,the_tile_count);
2158 pack_fclose(f);
2159 char tmpbuf[PATH_MAX+20]={0};
2160 sprintf(tmpbuf,"Saved %s",name);
2161 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2162 }
2163 }
2164 }
2165 }
2166
2167
2168 static DIALOG load_comboset_dlg[] =
2169 {
2170 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2171
2172
2173 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Set (Range)", NULL, NULL },
2174 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2175 //for future tabs
2176 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2177 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2178 //4
2179 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First:", NULL, NULL },
2180 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2181 //6
2182 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2183 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2184 //8
2185 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2186 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2187 { jwin_check_proc, 10, 46, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2188
2189 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2190 };
2191
2192 void writesomecombos(const char *prompt,int32_t initialval)
2193 {
2194
2195 char firsttile[8];
2196 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2197 sprintf(firsttile,"%d",0);
2198 //int32_t ret;
2199
2200
2201
2202 load_comboset_dlg[0].dp2 = get_zc_font(font_lfont);
2203
2204 sprintf(firsttile,"%d",0);
2205 //sprintf(tilecount,"%d",1);
2206
2207 load_comboset_dlg[5].dp = firsttile;
2208
2209 byte nooverwrite = 0;
2210
2211
2212 large_dialog(load_comboset_dlg);
2213
2214 int32_t ret = do_zqdialog(load_comboset_dlg,-1);
2215 jwin_center_dialog(load_comboset_dlg);
2216
2217 if(ret == 8)
2218 {
2219 if (load_comboset_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2220
2221 al_trace("Nooverwrite is: %d\n", nooverwrite);
2222 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2223 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2224 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2225 {
2226 char name[256];
2227 extract_name(temppath,name,FILENAMEALL);
2228 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2229 if(f)
2230 {
2231
2232 if (!readcombofile(f,first_tile_id,nooverwrite))
2233 {
2234 al_trace("Could not read from .zcombo packfile %s\n", name);
2235 jwin_alert("ZCOMBO File: Error","Could not load the specified combos.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2236 }
2237 else
2238 {
2239 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2240 saved=false;
2241 }
2242 pack_fclose(f);
2243 }
2244
2245 }
2246 }
2247 }
2248
2249 static DIALOG load_combopack_dlg[] =
2250 {
2251 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2252
2253
2254 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Import Full Combo Package 1:1", NULL, NULL },
2255 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2256 //for future tabs
2257 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2258 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2259 //4
2260 { d_dummy_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2261 { d_dummy_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2262 //6
2263 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2264 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2265 //8
2266 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2267 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2268 { jwin_check_proc, 10, 42, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2269
2270 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2271 };
2272
2273 void loadcombopack(const char *prompt,int32_t initialval)
2274 {
2275
2276 char firsttile[8];
2277 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2278 sprintf(firsttile,"%d",0);
2279 //int32_t ret;
2280
2281
2282
2283 load_combopack_dlg[0].dp2 = get_zc_font(font_lfont);
2284
2285 sprintf(firsttile,"%d",0);
2286 //sprintf(tilecount,"%d",1);
2287
2288 load_combopack_dlg[5].dp = firsttile;
2289
2290 byte nooverwrite = 0;
2291
2292
2293 large_dialog(load_combopack_dlg);
2294
2295 int32_t ret = do_zqdialog(load_combopack_dlg,-1);
2296 jwin_center_dialog(load_combopack_dlg);
2297
2298 if(ret == 8)
2299 {
2300 if (load_combopack_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2301
2302 al_trace("Nooverwrite is: %d\n", nooverwrite);
2303 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2304 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2305 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2306 {
2307 char name[256];
2308 extract_name(temppath,name,FILENAMEALL);
2309 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2310 if(f)
2311 {
2312 //need dialogue here
2313 if (!readcombofile(f,0,nooverwrite))
2314 {
2315 al_trace("Could not read from .zcombo packfile %s\n", name);
2316 jwin_alert("ZCOMBO File: Error","Could not load the specified Tile.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2317 }
2318 else
2319 {
2320 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2321 saved=false;
2322 }
2323 }
2324
2325 pack_fclose(f);
2326 }
2327 }
2328 }
2329
2330
2331 static DIALOG read_combopack_dlg[] =
2332 {
2333 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2334
2335
2336 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Combos (Specific Dest)", NULL, NULL },
2337 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2338 //for future tabs
2339 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2340 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2341 //4
2342 { jwin_text_proc, 10, 24, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2343 { jwin_edit_proc, 55, 22, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2344 //6
2345 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2346 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2347 //8
2348 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2349 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2350 //10
2351 { jwin_check_proc, 10, 58, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2352 //11
2353 { jwin_text_proc, 10, 42, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Skip:", NULL, NULL },
2354 //12
2355 { jwin_edit_proc, 55, 40, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2356
2357 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2358 };
2359
2360
2361
2362 void writesomecombos_to(const char *prompt,int32_t initialval)
2363 {
2364
2365 char firsttile[8];
2366 char skiptile[8];
2367 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2368 sprintf(firsttile,"%d",0);
2369 //int32_t ret;
2370
2371
2372
2373 read_combopack_dlg[0].dp2 = get_zc_font(font_lfont);
2374
2375 sprintf(skiptile,"%d",0);
2376 //sprintf(tilecount,"%d",1);
2377
2378 read_combopack_dlg[5].dp = firsttile;
2379
2380 byte nooverwrite = 0;
2381 int32_t skipover = 0;
2382
2383 sprintf(skiptile,"%d",0);
2384 //sprintf(tilecount,"%d",1);
2385
2386 read_combopack_dlg[12].dp = skiptile;
2387
2388 large_dialog(read_combopack_dlg);
2389
2390 int32_t ret = do_zqdialog(read_combopack_dlg,-1);
2391 jwin_center_dialog(read_combopack_dlg);
2392
2393 if(ret == 8)
2394 {
2395 if (read_combopack_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2396
2397 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2398 skipover = vbound(atoi(skiptile), 0, (MAXCOMBOS-1));
2399 al_trace("skipover is: %d\n", skipover);
2400 //skipover = vbound(skipover, 0, (MAXCOMBOS-1-skipover));
2401 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2402 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2403 {
2404 char name[256];
2405 extract_name(temppath,name,FILENAMEALL);
2406 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2407 if(f)
2408 {
2409
2410 if (!readcombofile_to_location(f,first_tile_id,nooverwrite, skipover))
2411 {
2412 al_trace("Could not read from .zcombo packfile %s\n", name);
2413 jwin_alert("ZCOMBO File: Error","Could not load the specified combos.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2414 }
2415 else
2416 {
2417 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2418 saved=false;
2419 }
2420 pack_fclose(f);
2421 }
2422
2423 }
2424 }
2425 }
2426
2427
2428
2429 static DIALOG save_dmaps_dlg[] =
2430 {
2431 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2432
2433
2434 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save DMaps (.zdmap)", NULL, NULL },
2435 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2436 //for future tabs
2437 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2438 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2439 //4
2440 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2441 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2442 //6
2443 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Last", NULL, NULL },
2444 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2445 //8
2446 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2447 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2448 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2449 };
2450
2451
2452 void savesomedmaps(const char *prompt,int32_t initialval)
2453 {
2454
2455 char firstdmap[8], lastdmap[8];
2456 int32_t first_dmap_id = 0; int32_t last_dmap_id = 0;
2457 sprintf(firstdmap,"%d",0);
2458 sprintf(lastdmap,"%d",1);
2459 //int32_t ret;
2460
2461
2462
2463 save_dmaps_dlg[0].dp2 = get_zc_font(font_lfont);
2464
2465 sprintf(firstdmap,"%d",0);
2466 sprintf(lastdmap,"%d",0);
2467
2468 save_dmaps_dlg[5].dp = firstdmap;
2469 save_dmaps_dlg[7].dp = lastdmap;
2470
2471 large_dialog(save_dmaps_dlg);
2472
2473 int32_t ret = do_zqdialog(save_dmaps_dlg,-1);
2474 jwin_center_dialog(save_dmaps_dlg);
2475
2476 if(ret == 8)
2477 {
2478 first_dmap_id = vbound(atoi(firstdmap), 0, MAXDMAPS-1);
2479 last_dmap_id = vbound(atoi(lastdmap), 0, MAXDMAPS-1);
2480
2481 if ( last_dmap_id < first_dmap_id )
2482 {
2483 int32_t swap = last_dmap_id;
2484 last_dmap_id = first_dmap_id;
2485 first_dmap_id = swap;
2486 }
2487 if(!prompt_for_new_file_compat("Export DMaps (.zdmap)","zdmap",NULL,datapath,false))
2488
2489
2490 saved=false;
2491
2492 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2493 if(f)
2494 {
2495 if(!writesomedmaps(f,first_dmap_id,last_dmap_id,MAXDMAPS))
2496 {
2497 char buf[PATH_MAX+20],name[PATH_MAX];
2498 extract_name(temppath,name,FILENAMEALL);
2499 sprintf(buf,"Unable to load %s",name);
2500 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2501 }
2502 else
2503 {
2504 char name[PATH_MAX];
2505 extract_name(temppath,name,FILENAMEALL);
2506 char tmpbuf[PATH_MAX+20]={0};
2507 sprintf(tmpbuf,"Saved %s",name);
2508 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2509 }
2510 }
2511 pack_fclose(f);
2512 }
2513 }
2514
2515 static DIALOG save_comboaliasfiles_dlg[] =
2516 {
2517 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2518
2519
2520 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Combo Alias Pack", NULL, NULL },
2521 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2522 //for future tabs
2523 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2524 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2525 //4
2526 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2527 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2528 //6
2529 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2530 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2531 //8
2532 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2533 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2534 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2535 };
2536
2537
2538 void savesomecomboaliases(const char *prompt,int32_t initialval)
2539 {
2540
2541 char firsttile[8], tilecount[8];
2542 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2543 sprintf(firsttile,"%d",0);
2544 sprintf(tilecount,"%d",1);
2545 //int32_t ret;
2546
2547
2548
2549 save_comboaliasfiles_dlg[0].dp2 = get_zc_font(font_lfont);
2550
2551 sprintf(firsttile,"%d",0);
2552 sprintf(tilecount,"%d",1);
2553
2554 save_comboaliasfiles_dlg[5].dp = firsttile;
2555 save_comboaliasfiles_dlg[7].dp = tilecount;
2556
2557 large_dialog(save_comboaliasfiles_dlg);
2558
2559 int32_t ret = do_zqdialog(save_comboaliasfiles_dlg,-1);
2560 jwin_center_dialog(save_comboaliasfiles_dlg);
2561
2562 if(ret == 8)
2563 {
2564 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOALIASES-1));
2565 the_tile_count = vbound(atoi(tilecount), 1, (MAXCOMBOALIASES-1)-first_tile_id);
2566 if(prompt_for_new_file_compat("Save ZALIAS(.zalias)", "zalias", NULL,datapath,false))
2567 {
2568 char name[PATH_MAX];
2569 extract_name(temppath,name,FILENAMEALL);
2570 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2571 if(f)
2572 {
2573 writecomboaliasfile(f,first_tile_id,the_tile_count);
2574 pack_fclose(f);
2575 char tmpbuf[PATH_MAX+20]={0};
2576 sprintf(tmpbuf,"Saved %s",name);
2577 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2578 }
2579 }
2580 }
2581 }
2582
2583
2584 static DIALOG read_comboaliaspack_dlg[] =
2585 {
2586 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2587
2588
2589 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Combo Pack To:", NULL, NULL },
2590 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2591 //for future tabs
2592 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2593 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2594 //4
2595 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2596 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2597 //6
2598 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2599 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2600 //8
2601 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2602 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2603 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2604 };
2605
2606
2607 void writesomecomboaliases_to(const char *prompt,int32_t initialval)
2608 {
2609
2610 char firsttile[8];;
2611 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2612 sprintf(firsttile,"%d",0);
2613 //int32_t ret;
2614
2615
2616
2617 read_comboaliaspack_dlg[0].dp2 = get_zc_font(font_lfont);
2618
2619 sprintf(firsttile,"%d",0);
2620 //sprintf(tilecount,"%d",1);
2621
2622 read_comboaliaspack_dlg[5].dp = firsttile;
2623
2624 large_dialog(read_comboaliaspack_dlg);
2625
2626 int32_t ret = do_zqdialog(read_comboaliaspack_dlg,-1);
2627 jwin_center_dialog(read_comboaliaspack_dlg);
2628
2629 if(ret == 8)
2630 {
2631 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOALIASES-1));
2632 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2633 if(prompt_for_existing_file_compat("Load ZALIAS(.zalias)", "zalias", NULL,datapath,false))
2634 {
2635 char name[256];
2636 extract_name(temppath,name,FILENAMEALL);
2637 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2638 if(f)
2639 {
2640
2641 if (!readcomboaliasfile_to_location(f,first_tile_id))
2642 {
2643 al_trace("Could not read from .zcombo packfile %s\n", name);
2644 jwin_alert("ZALIAS File: Error","Could not load the specified combo aliases.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2645 }
2646 else
2647 {
2648 jwin_alert("ZALIAS File: Success!","Loaded the source combos to your combo alias table!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2649 saved=false;
2650 }
2651 pack_fclose(f);
2652 }
2653 }
2654 }
2655 }
2656
2657
2658
2659
2660 //Doorsets
2661
2662 static DIALOG save_doorset_dlg[] =
2663 {
2664 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2665 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Doorset", NULL, NULL },
2666 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2667 //for future tabs
2668 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2669 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2670 //4
2671 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2672 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2673 //6
2674 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2675 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2676 //8
2677 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2678 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2679 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2680 };
2681
2682
2683 void do_exportdoorset(const char *prompt,int32_t initialval)
2684 {
2685 char firstdoor[8], doorct[8];
2686 int32_t first_doorset_id = 0; int32_t the_doorset_count = 1;
2687 sprintf(firstdoor,"%d",0);
2688 sprintf(doorct,"%d",1);
2689 //int32_t ret;
2690 save_doorset_dlg[0].dp2 = get_zc_font(font_lfont);
2691
2692 sprintf(firstdoor,"%d",0);
2693 sprintf(doorct,"%d",1);
2694
2695 save_doorset_dlg[5].dp = firstdoor;
2696 save_doorset_dlg[7].dp = doorct;
2697
2698 large_dialog(save_doorset_dlg);
2699
2700 int32_t ret = do_zqdialog(save_doorset_dlg,-1);
2701 jwin_center_dialog(save_doorset_dlg);
2702
2703 if(ret == 8) //OK
2704 {
2705 /* sanity bounds
2706 first_doorset_id = vbound(atoi(firstdoor), 0, (MAXCOMBOS-1));
2707 the_doorset_count = vbound(atoi(doorct), 1, (MAXCOMBOS-1)-first_doorset_id);
2708 */
2709 if(prompt_for_new_file_compat("Save ZDOORS(.zdoors)", "zdoors", NULL,datapath,false))
2710 {
2711 char name[256];
2712 extract_name(temppath,name,FILENAMEALL);
2713 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2714 if(f)
2715 {
2716 writezdoorsets(f,first_doorset_id,the_doorset_count);
2717 pack_fclose(f);
2718 char tmpbuf[512]={0};
2719 sprintf(tmpbuf,"Saved %s",name);
2720 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2721 }
2722 }
2723 }
2724 }
2725
2726 static DIALOG load_doorset_dlg[] =
2727 {
2728 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2729 { jwin_win_proc, 0, 0, 120, 124, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Door Set (Range)", NULL, NULL },
2730 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2731 //for future tabs
2732 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2733 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2734 //4
2735 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First:", NULL, NULL },
2736 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2737 //6
2738 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2739 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2740 //8
2741 { jwin_button_proc, 15, 92, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2742 { jwin_button_proc, 69, 92, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2743 //10
2744 { jwin_text_proc, 10, 64, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Dest", NULL, NULL },
2745 { jwin_edit_proc, 55, 63, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2746 //8
2747
2748 // { jwin_check_proc, 10, 46, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2749
2750 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2751 };
2752
2753 void do_importdoorset(const char *prompt,int32_t initialval)
2754 {
2755
2756 char firstdoor[8], doorct[8], destid[8];
2757 int32_t first_doorset_id = 0; int32_t the_doorset_count = 1;
2758 int32_t the_dest_id = 0;
2759 sprintf(firstdoor,"%d",0);
2760 sprintf(doorct,"%d",1);
2761 sprintf(destid,"%d",0);
2762 //int32_t ret;
2763
2764 save_doorset_dlg[0].dp2 = get_zc_font(font_lfont);
2765
2766 load_doorset_dlg[5].dp = firstdoor;
2767 load_doorset_dlg[7].dp = doorct;
2768 load_doorset_dlg[11].dp = destid;
2769
2770 byte nooverwrite = 0;
2771
2772 large_dialog(load_doorset_dlg);
2773
2774 int32_t ret = do_zqdialog(load_doorset_dlg,-1);
2775 jwin_center_dialog(load_doorset_dlg);
2776
2777 if(ret == 8) //OK
2778 {
2779 //if (load_doorset_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2780
2781 //sanity bound
2782 first_doorset_id = vbound(atoi(firstdoor), 0, door_combo_set_count);
2783 the_doorset_count = vbound(atoi(doorct), 1, door_combo_set_count);
2784 the_dest_id = vbound(atoi(destid), 0, door_combo_set_count);
2785 if(prompt_for_existing_file_compat("Load ZDOORS(.zdoors)", "zdoors", NULL,datapath,false))
2786 {
2787 char name[256];
2788 extract_name(temppath,name,FILENAMEALL);
2789 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2790 if(f)
2791 {
2792 int32_t ret = readzdoorsets(f,first_doorset_id,the_doorset_count, the_dest_id);
2793
2794 if (!ret)
2795 {
2796 al_trace("Could not read from .zdoors packfile %s\n", name);
2797 jwin_alert("ZDOORS File: Error","Could not load the specified doorsets.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2798 }
2799 else if ( ret == 1 )
2800 {
2801 jwin_alert("ZDOORS File: Success!","Loaded the source doorsets!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2802 saved=false;
2803 }
2804 else if ( ret == 2 )
2805 {
2806 jwin_alert("ZDOORS File: Issue:","Targets exceed doorset count!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2807 saved=false;
2808 }
2809 pack_fclose(f);
2810 }
2811 }
2812 }
2813 }
2814
2815 int32_t gettilepagenumber(const char *prompt, int32_t initialval)
2816 {
2817 char buf[20];
2818 sprintf(buf,"%d",initialval);
2819 getnum_dlg[0].dp=(void *)prompt;
2820 getnum_dlg[0].dp2=get_zc_font(font_lfont);
2821 getnum_dlg[2].dp=buf;
2822
2823 large_dialog(getnum_dlg);
2824
2825 int32_t ret = do_zqdialog(getnum_dlg,2);
2826
2827 if(ret==3)
2828 return atoi(buf);
2829
2830 return -1;
2831 }
2832
2833 int32_t gethexnumber(const char *prompt,int32_t initialval)
2834 {
2835 cancelgetnum=true;
2836 char buf[20];
2837 sprintf(buf,"%X",initialval);
2838 getnum_dlg[0].dp=(void *)prompt;
2839 getnum_dlg[0].dp2=get_zc_font(font_lfont);
2840 getnum_dlg[2].dp=(void *)buf;
2841
2842 large_dialog(getnum_dlg);
2843
2844 int32_t ret=do_zqdialog(getnum_dlg,2);
2845
2846 if(ret!=0&&ret!=4)
2847 {
2848 cancelgetnum=false;
2849 }
2850
2851 if(ret==3)
2852 return zc_xtoi(buf);
2853
2854 return initialval;
2855 }
2856
2857 void update_combo_cycling()
2858 {
2859 Map.update_combo_cycling();
2860 }
2861
2862 void update_freeform_combos()
2863 {
2864 Map.update_freeform_combos();
2865 }
2866
2867 bool layers_valid(mapscr *tempscr)
2868 {
2869 for(int32_t i=0; i<6; i++)
2870 {
2871 if(tempscr->layermap[i]>map_count)
2872 {
2873 return false;
2874 }
2875 }
2876
2877 return true;
2878 }
2879
2880 void fix_layers(mapscr *tempscr, bool showwarning)
2881 {
2882 char buf[80]="layers have been changed: ";
2883
2884 for(int32_t i=0; i<6; i++)
2885 {
2886 if(tempscr->layermap[i]>map_count)
2887 {
2888 strcat(buf, "%d ");
2889 sprintf(buf, buf, i+1);
2890 tempscr->layermap[i]=0;
2891 }
2892 }
2893
2894 if(showwarning)
2895 {
2896 jwin_alert("Invalid layers detected",
2897 "One or more layers on this screen used",
2898 "maps that do not exist. The settings of these",
2899 buf, "O&K", NULL, 'o', 0, get_zc_font(font_lfont));
2900 }
2901 }
2902
2903 extern const char *colorlist(int32_t index, int32_t *list_size);
2904
2905 static char autobackup_str_buf[32];
2906 const char *autobackuplist(int32_t index, int32_t *list_size)
2907 {
2908 if(index>=0)
2909 {
2910 bound(index,0,10);
2911
2912 if(index==0)
2913 {
2914 sprintf(autobackup_str_buf,"Disabled");
2915 }
2916 else
2917 {
2918 sprintf(autobackup_str_buf,"%2d",index);
2919 }
2920
2921 return autobackup_str_buf;
2922 }
2923
2924 *list_size=11;
2925 return NULL;
2926 }
2927
2928 static char autosave_str_buf[32];
2929 const char *autosavelist(int32_t index, int32_t *list_size)
2930 {
2931 if(index>=0)
2932 {
2933 bound(index,0,10);
2934
2935 if(index==0)
2936 {
2937 sprintf(autosave_str_buf,"Disabled");
2938 }
2939 else
2940 {
2941 sprintf(autosave_str_buf,"%2d Minute%c",index,index>1?'s':0);
2942 }
2943
2944 return autosave_str_buf;
2945 }
2946
2947 *list_size=11;
2948 return NULL;
2949 }
2950
2951 const char *autosavelist2(int32_t index, int32_t *list_size)
2952 {
2953 if(index>=0)
2954 {
2955 bound(index,0,9);
2956 sprintf(autosave_str_buf,"%2d",index+1);
2957 return autosave_str_buf;
2958 }
2959
2960 *list_size=10;
2961 return NULL;
2962 }
2963
2964
2965 static int32_t options_1_list[] =
2966 {
2967 // dialog control number
2968 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, -1
2969 };
2970
2971 static int32_t options_2_list[] =
2972 {
2973 // dialog control number
2974 50, 51, -1
2975 };
2976
2977 static int32_t options_3_list[] =
2978 {
2979 // dialog control number
2980 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, -1
2981 };
2982 static int32_t options_4_list[] =
2983 {
2984 57, 58, 59, 60,
2985 -1
2986 };
2987
2988 static TABPANEL options_tabs[] =
2989 {
2990 // (text)
2991 { (char *)" 1 ", D_SELECTED, options_1_list, 0, NULL },
2992 { (char *)" 2 ", 0, options_2_list, 0, NULL },
2993 { (char *)" 3 ", 0, options_3_list, 0, NULL },
2994 { (char *)" 4 ", 0, options_4_list, 0, NULL },
2995 { NULL, 0, NULL, 0, NULL }
2996 };
2997
2998 12 static ListData autobackup_list(autobackuplist, &font);
2999 12 static ListData autosave_list(autosavelist, &font);
3000 12 static ListData autosave_list2(autosavelist2, &font);
3001 12 static ListData color_list(colorlist, &font);
3002 12 static ListData snapshotformat_list(snapshotformatlist, &font);
3003
3004 const char *dm_names[dm_max]=
3005 {
3006 "Normal",
3007 "Relational", // Removed.
3008 "Dungeon", // Removed.
3009 "Alias",
3010 "Pool",
3011 "Auto"
3012 };
3013
3014 void fix_drawing_mode_menu()
3015 {
3016 drawing_mode_menu.select_only_uid(draw_mode);
3017 }
3018
3019 int32_t onDrawingMode()
3020 {
3021 draw_mode=(draw_mode+1)%dm_max;
3022 int dm_relational = 1;
3023 if ((int)draw_mode == dm_relational)
3024 draw_mode += 2;
3025 fix_drawing_mode_menu();
3026 restore_mouse();
3027 return D_O_K;
3028 }
3029
3030 int32_t onDrawingModeNormal()
3031 {
3032 draw_mode=dm_normal;
3033 fix_drawing_mode_menu();
3034 restore_mouse();
3035 return D_O_K;
3036 }
3037
3038 int32_t onDrawingModeAlias()
3039 {
3040 if(draw_mode==dm_alias)
3041 {
3042 return onDrawingModeNormal();
3043 }
3044
3045 draw_mode=dm_alias;
3046 alias_cset_mod=0;
3047 fix_drawing_mode_menu();
3048 restore_mouse();
3049 return D_O_K;
3050 }
3051
3052 int32_t onDrawingModePool()
3053 {
3054 if(draw_mode==dm_cpool)
3055 {
3056 return onDrawingModeNormal();
3057 }
3058
3059 draw_mode=dm_cpool;
3060 fix_drawing_mode_menu();
3061 restore_mouse();
3062 return D_O_K;
3063 }
3064
3065 int32_t onDrawingModeAuto()
3066 {
3067 if (draw_mode == dm_auto)
3068 {
3069 return onDrawingModeNormal();
3070 }
3071
3072 draw_mode = dm_auto;
3073 fix_drawing_mode_menu();
3074 restore_mouse();
3075 return D_O_K;
3076 }
3077
3078 int32_t onReTemplate()
3079 {
3080 if(jwin_alert("Confirm Overwrite","Apply NES Dungeon template to","all screens on this map?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
3081 {
3082 Map.TemplateAll();
3083 refresh(rALL);
3084 }
3085
3086 return D_O_K;
3087 }
3088
3089 int32_t onUndo()
3090 {
3091 Map.UndoCommand();
3092 refresh(rALL);
3093 return D_O_K;
3094 }
3095
3096 int32_t onRedo()
3097 {
3098 Map.RedoCommand();
3099 refresh(rALL);
3100 return D_O_K;
3101 }
3102
3103 int32_t onCopy()
3104 {
3105 if(prv_mode)
3106 {
3107 Map.set_prvcmb(Map.get_prvcmb()==0?1:0);
3108 return D_O_K;
3109 }
3110
3111 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3112 Map.Copy(screen);
3113 return D_O_K;
3114 }
3115
3116 int32_t onPaste()
3117 {
3118 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
3119 {
3120 if(CHECK_CTRL_CMD)
3121 return onPasteAllToAll();
3122 else return onPasteAll();
3123 }
3124 else if(CHECK_CTRL_CMD)
3125 return onPasteToAll();
3126 else
3127 {
3128 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3129 Map.DoPasteScreenCommand(PasteCommandType::ScreenPartial, screen);
3130 }
3131 return D_O_K;
3132 }
3133
3134 int32_t onPasteAll()
3135 {
3136 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3137 Map.DoPasteScreenCommand(PasteCommandType::ScreenAll, screen);
3138 return D_O_K;
3139 }
3140
3141 int32_t onPasteToAll()
3142 {
3143 if(confirmBox("You are about to paste to all screens on the current map."))
3144 {
3145 Map.DoPasteScreenCommand(PasteCommandType::ScreenPartialToEveryScreen);
3146 }
3147 return D_O_K;
3148 }
3149
3150 int32_t onPasteAllToAll()
3151 {
3152 if(confirmBox("You are about to paste to all screens on the current map."))
3153 {
3154 Map.DoPasteScreenCommand(PasteCommandType::ScreenAllToEveryScreen);
3155 }
3156 return D_O_K;
3157 }
3158
3159 int32_t onPasteUnderCombo()
3160 {
3161 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3162 Map.DoPasteScreenCommand(PasteCommandType::ScreenUnderCombo, screen);
3163 return D_O_K;
3164 }
3165
3166 int32_t onPasteSecretCombos()
3167 {
3168 Map.DoPasteScreenCommand(PasteCommandType::ScreenSecretCombos);
3169 return D_O_K;
3170 }
3171
3172 int32_t onPasteFFCombos()
3173 {
3174 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3175 Map.DoPasteScreenCommand(PasteCommandType::ScreenFFCombos, screen);
3176 return D_O_K;
3177 }
3178
3179 int32_t onPasteWarps()
3180 {
3181 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3182 Map.DoPasteScreenCommand(PasteCommandType::ScreenWarps, screen);
3183 return D_O_K;
3184 }
3185
3186 int32_t onPasteScreenData()
3187 {
3188 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3189 Map.DoPasteScreenCommand(PasteCommandType::ScreenData, screen);
3190 return D_O_K;
3191 }
3192
3193 int32_t onPasteWarpLocations()
3194 {
3195 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3196 Map.DoPasteScreenCommand(PasteCommandType::ScreenWarpLocations, screen);
3197 return D_O_K;
3198 }
3199
3200 int32_t onPasteDoors()
3201 {
3202 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3203 Map.DoPasteScreenCommand(PasteCommandType::ScreenDoors, screen);
3204 return D_O_K;
3205 }
3206
3207 int32_t onPasteLayers()
3208 {
3209 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3210 Map.DoPasteScreenCommand(PasteCommandType::ScreenLayers, screen);
3211 return D_O_K;
3212 }
3213
3214 int32_t onPastePalette()
3215 {
3216 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3217 Map.DoPasteScreenCommand(PasteCommandType::ScreenPalette, screen);
3218 return D_O_K;
3219 }
3220
3221 int32_t onPasteRoom()
3222 {
3223 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3224 Map.DoPasteScreenCommand(PasteCommandType::ScreenRoom, screen);
3225 return D_O_K;
3226 }
3227
3228 int32_t onPasteGuy()
3229 {
3230 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3231 Map.DoPasteScreenCommand(PasteCommandType::ScreenGuy, screen);
3232 return D_O_K;
3233 }
3234
3235 int32_t onPasteEnemies()
3236 {
3237 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3238 Map.DoPasteScreenCommand(PasteCommandType::ScreenEnemies, screen);
3239 return D_O_K;
3240 }
3241
3242 int32_t onDelete()
3243 {
3244 restore_mouse();
3245
3246 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3247 mapscr* scr = active_visible_screen ? active_visible_screen->scr : Map.CurrScr();
3248 if(!(scr->valid&mVALID) || jwin_alert("Confirm Delete","Delete this screen?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3249 {
3250 Map.DoClearScreenCommand(screen);
3251 }
3252
3253 saved=false;
3254 return D_O_K;
3255 }
3256
3257 int32_t onDeleteMap()
3258 {
3259 if(jwin_alert("Confirm Delete","Clear this entire map?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3260 {
3261 Map.clearmap(false);
3262 refresh(rALL);
3263 saved=false;
3264 }
3265
3266 return D_O_K;
3267 }
3268
3269 int32_t onToggleDarkness()
3270 {
3271 Map.CurrScr()->flags^=4;
3272 refresh(rMAP+rMENU);
3273 saved=false;
3274 return D_O_K;
3275 }
3276
3277 int32_t onIncMap()
3278 {
3279 int32_t m=Map.getCurrMap();
3280 Map.setCurrMap(m+1>=map_count?0:m+1);
3281 Map.setlayertarget(); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3282
3283 refresh(rALL);
3284 return D_O_K;
3285 }
3286
3287 int32_t onDecMap()
3288 {
3289 int32_t m = Map.getCurrMap();
3290 Map.setCurrMap((m-1<0)?map_count-1:zc_min(m-1,map_count-1));
3291 // Map.setCurrScr(Map.getCurrScr()); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3292 Map.setlayertarget(); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3293
3294 Map.refresh_color();
3295
3296 refresh(rALL);
3297 return D_O_K;
3298 }
3299
3300
3301 int32_t onDefault_Pals()
3302 {
3303 if(jwin_alert("Confirm Reset","Reset all palette data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3304 {
3305 saved=false;
3306
3307 if(!init_colordata(true, &header, &QMisc))
3308 {
3309 jwin_alert("Error","Palette reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3310 }
3311
3312 refresh_pal();
3313 }
3314
3315 return D_O_K;
3316 }
3317
3318 int32_t onDefault_Combos()
3319 {
3320 if(jwin_alert("Confirm Reset","Reset combo data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3321 {
3322 saved=false;
3323
3324 if(!init_combos(true, &header))
3325 {
3326 jwin_alert("Error","Combo reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3327 }
3328
3329 refresh(rALL);
3330 }
3331
3332 return D_O_K;
3333 }
3334
3335 int32_t onDefault_Items()
3336 {
3337 if(jwin_alert("Confirm Reset","Reset all items?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3338 {
3339 saved=false;
3340 reset_items(true, &header);
3341 }
3342
3343 return D_O_K;
3344 }
3345
3346 int32_t onDefault_Weapons()
3347 {
3348 if(jwin_alert("Confirm Reset","Reset weapon/misc. sprite data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3349 {
3350 saved=false;
3351 reset_wpns(true, &header);
3352 }
3353
3354 return D_O_K;
3355 }
3356
3357 int32_t onDefault_Guys()
3358 {
3359 if(jwin_alert("Confirm Reset","Reset all enemy/NPC data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3360 {
3361 saved=false;
3362 reset_guys();
3363 }
3364
3365 return D_O_K;
3366 }
3367
3368
3369 int32_t onDefault_Tiles()
3370 {
3371 if(jwin_alert("Confirm Reset","Reset all tiles?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3372 {
3373 saved=false;
3374
3375 if(!init_tiles(true, &header))
3376 {
3377 jwin_alert("Error","Tile reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3378 }
3379
3380 refresh(rALL);
3381 }
3382
3383 return D_O_K;
3384 }
3385
3386 void change_sfx(SAMPLE *sfx1, SAMPLE *sfx2);
3387
3388 int32_t onDefault_SFX()
3389 {
3390 if(jwin_alert("Confirm Reset","Reset all sound effects?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3391 {
3392 saved=false;
3393 SAMPLE *temp_sample;
3394
3395 for(int32_t i=1; i<WAV_COUNT; i++)
3396 {
3397 temp_sample = (SAMPLE *)sfxdata[zc_min(i,Z35)].dat;
3398 change_sfx(&customsfxdata[i], temp_sample);
3399 sprintf(sfx_string[i],"s%03d",i);
3400
3401 if(i<Z35)
3402 strcpy(sfx_string[i], old_sfx_string[i-1]);
3403 set_bit(customsfxflag, i<Z35?1:0, i-1);
3404 }
3405 }
3406
3407 return D_O_K;
3408 }
3409
3410
3411 int32_t onDefault_MapStyles()
3412 {
3413 if(jwin_alert("Confirm Reset","Reset all map styles?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3414 {
3415 saved=false;
3416 reset_mapstyles(true, &QMisc);
3417 }
3418
3419 return D_O_K;
3420 }
3421
3422 int onScrollScreen(int dir, bool warp)
3423 {
3424 Map.scroll(dir,warp);
3425 return D_O_K;
3426 }
3427
3428 int32_t onComboColLeft()
3429 {
3430 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3431 ;
3432 else if((First[current_combolist]>0)&&(draw_mode!=dm_alias))
3433 {
3434 First[current_combolist]-=1;
3435 clear_tooltip();
3436 refresh(rCOMBOS);
3437 }
3438 else if((combo_alistpos[current_comboalist]>0)&&(draw_mode==dm_alias))
3439 {
3440 combo_alistpos[current_comboalist]-=1;
3441 clear_tooltip();
3442 refresh(rCOMBOS);
3443 }
3444
3445 clear_keybuf();
3446 return D_O_K;
3447 }
3448
3449 int32_t onComboColRight()
3450 {
3451 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3452 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3453 ;
3454 else if((First[current_combolist]<(MAXCOMBOS-(sqr.w*sqr.h)))&&(draw_mode!=dm_alias))
3455 {
3456 First[current_combolist]+=1;
3457 clear_tooltip();
3458 refresh(rCOMBOS);
3459 }
3460 else if((combo_alistpos[current_comboalist]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))&&(draw_mode==dm_alias))
3461 {
3462 combo_alistpos[current_comboalist]+=1;
3463 clear_tooltip();
3464 refresh(rCOMBOS);
3465 }
3466
3467 clear_keybuf();
3468 return D_O_K;
3469 }
3470
3471 int32_t onComboColUp()
3472 {
3473 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3474 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3475 ;
3476 else if((First[current_combolist]>0)&&(draw_mode!=dm_alias))
3477 {
3478 First[current_combolist]-=zc_min(First[current_combolist],sqr.w);
3479 clear_tooltip();
3480
3481 refresh(rCOMBOS);
3482 }
3483 else if((combo_alistpos[current_comboalist]>0)&&(draw_mode==dm_alias))
3484 {
3485 combo_alistpos[current_comboalist]-=zc_min(combo_alistpos[current_comboalist],sqr.w);
3486 clear_tooltip();
3487 refresh(rCOMBOS);
3488 }
3489
3490 clear_keybuf();
3491 return D_O_K;
3492 }
3493
3494 int32_t onComboColDown()
3495 {
3496 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3497
3498 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3499 ;
3500 else if((First[current_combolist]<(MAXCOMBOS-(sqr.w*sqr.h)))&&(draw_mode!=dm_alias))
3501 {
3502 First[current_combolist]+=zc_min((MAXCOMBOS-sqr.w)-First[current_combolist],sqr.w);
3503 clear_tooltip();
3504 refresh(rCOMBOS);
3505 }
3506 else if((combo_alistpos[current_comboalist]<(MAXCOMBOALIASES-(comboaliaslist[0].w*comboaliaslist[0].h)))&&(draw_mode==dm_alias))
3507 {
3508 combo_alistpos[current_comboalist]+=zc_min((MAXCOMBOALIASES-sqr.w)-combo_alistpos[current_comboalist],sqr.w);
3509 clear_tooltip();
3510 refresh(rCOMBOS);
3511 }
3512
3513 clear_keybuf();
3514 return D_O_K;
3515 }
3516
3517 void scrollup(int j)
3518 {
3519 switch(draw_mode)
3520 {
3521 case dm_alias:
3522 {
3523 auto& sqr = comboaliaslist[j];
3524 if(combo_alistpos[j]>0)
3525 {
3526 if(CHECK_CTRL_CMD)
3527 {
3528 combo_alistpos[j]=0;
3529 clear_tooltip();
3530 }
3531 else
3532 {
3533 combo_alistpos[j]-=zc_min(combo_alistpos[j],(sqr.w*sqr.h));
3534 clear_tooltip();
3535 }
3536
3537 refresh(rCOMBOS);
3538 }
3539 break;
3540 }
3541 case dm_cpool:
3542 {
3543 auto& sqr = comboaliaslist[j];
3544 if(combo_pool_listpos[j]>0)
3545 {
3546 if(CHECK_CTRL_CMD)
3547 {
3548 combo_pool_listpos[j]=0;
3549 clear_tooltip();
3550 }
3551 else
3552 {
3553 combo_pool_listpos[j]-=zc_min(combo_pool_listpos[j],(sqr.w*sqr.h));
3554 clear_tooltip();
3555 }
3556
3557 refresh(rCOMBOS);
3558 }
3559 break;
3560 }
3561 case dm_auto:
3562 {
3563 auto& sqr = comboaliaslist[j];
3564 if (combo_auto_listpos[j] > 0)
3565 {
3566 if (CHECK_CTRL_CMD)
3567 {
3568 combo_auto_listpos[j] = 0;
3569 clear_tooltip();
3570 }
3571 else
3572 {
3573 combo_auto_listpos[j] -= zc_min(combo_auto_listpos[j], (sqr.w * sqr.h));
3574 clear_tooltip();
3575 }
3576
3577 refresh(rCOMBOS);
3578 }
3579 break;
3580 }
3581 default:
3582 {
3583 auto& sqr = combolist[j];
3584 if(First[j]>0)
3585 {
3586 if(CHECK_CTRL_CMD)
3587 {
3588 First[j]-=zc_min(First[j],256);
3589 clear_tooltip();
3590 }
3591 else
3592 {
3593 First[j]-=zc_min(First[j],(sqr.w*sqr.h));
3594 clear_tooltip();
3595 }
3596
3597 refresh(rCOMBOS);
3598 }
3599 break;
3600 }
3601 }
3602 }
3603 void scrolldown(int j)
3604 {
3605 switch(draw_mode)
3606 {
3607 case dm_alias:
3608 {
3609 auto& sqr = comboaliaslist[j];
3610 if(combo_alistpos[j]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))
3611 {
3612 if(CHECK_CTRL_CMD)
3613 {
3614 combo_alistpos[j]=MAXCOMBOALIASES-(sqr.w*sqr.h);
3615 clear_tooltip();
3616 }
3617 else
3618 {
3619 combo_alistpos[j]=zc_min((MAXCOMBOALIASES-(sqr.w*sqr.h)),combo_alistpos[j]+(sqr.w*sqr.h));
3620 clear_tooltip();
3621 }
3622
3623 refresh(rCOMBOS);
3624 }
3625 break;
3626 }
3627 case dm_cpool:
3628 {
3629 auto& sqr = comboaliaslist[j];
3630 if(combo_pool_listpos[j]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))
3631 {
3632 if(CHECK_CTRL_CMD)
3633 {
3634 combo_pool_listpos[j]=MAXCOMBOALIASES-(sqr.w*sqr.h);
3635 clear_tooltip();
3636 }
3637 else
3638 {
3639 combo_pool_listpos[j]=zc_min((MAXCOMBOALIASES-(sqr.w*sqr.h)),combo_pool_listpos[j]+(sqr.w*sqr.h));
3640 clear_tooltip();
3641 }
3642
3643 refresh(rCOMBOS);
3644 }
3645 break;
3646 }
3647 case dm_auto:
3648 {
3649 auto& sqr = comboaliaslist[j];
3650 if (combo_auto_listpos[j] < (MAXCOMBOALIASES - (sqr.w * sqr.h)))
3651 {
3652 if (CHECK_CTRL_CMD)
3653 {
3654 combo_auto_listpos[j] = MAXCOMBOALIASES - (sqr.w * sqr.h);
3655 clear_tooltip();
3656 }
3657 else
3658 {
3659 combo_auto_listpos[j] = zc_min((MAXCOMBOALIASES - (sqr.w * sqr.h)), combo_pool_listpos[j] + (sqr.w * sqr.h));
3660 clear_tooltip();
3661 }
3662
3663 refresh(rCOMBOS);
3664 }
3665 break;
3666 }
3667 default:
3668 {
3669 auto& sqr = combolist[j];
3670 if(First[j]<(MAXCOMBOS-(sqr.w*sqr.h)))
3671 {
3672 if(CHECK_CTRL_CMD)
3673 {
3674 First[j]=zc_min((MAXCOMBOS-sqr.w*sqr.h),First[j]+256);
3675 clear_tooltip();
3676 }
3677 else
3678 {
3679 First[j]=zc_min((MAXCOMBOS-(sqr.w*sqr.h)),First[j]+(sqr.w*sqr.h));
3680 clear_tooltip();
3681 }
3682
3683 refresh(rCOMBOS);
3684 }
3685 break;
3686 }
3687 }
3688 }
3689
3690 int32_t onPgUp()
3691 {
3692 switch(draw_mode)
3693 {
3694 case dm_alias:
3695 scrollup(current_comboalist);
3696 break;
3697 case dm_cpool:
3698 scrollup(current_cpoollist);
3699 break;
3700 case dm_auto:
3701 scrollup(current_cautolist);
3702 break;
3703 default:
3704 scrollup(current_combolist);
3705 break;
3706 }
3707 return D_O_K;
3708 }
3709
3710 int32_t onPgDn()
3711 {
3712 switch(draw_mode)
3713 {
3714 case dm_alias:
3715 scrolldown(current_comboalist);
3716 break;
3717 case dm_cpool:
3718 scrolldown(current_cpoollist);
3719 break;
3720 case dm_auto:
3721 scrolldown(current_cautolist);
3722 break;
3723 default:
3724 scrolldown(current_combolist);
3725 break;
3726 }
3727 return D_O_K;
3728 }
3729
3730 int32_t onIncreaseCSet()
3731 {
3732 if(draw_mode!=dm_alias)
3733 {
3734 CSet=wrap(CSet+1,0,13);
3735 refresh(rCOMBOS+rMENU+rCOMBO);
3736 }
3737 else
3738 {
3739 alias_cset_mod=wrap(alias_cset_mod+1,0,13);
3740 }
3741 return D_O_K;
3742 }
3743
3744 int32_t onDecreaseCSet()
3745 {
3746 if(draw_mode!=dm_alias)
3747 {
3748 CSet=wrap(CSet-1,0,13);
3749 refresh(rCOMBOS+rMENU+rCOMBO);
3750 }
3751 else
3752 {
3753 alias_cset_mod=wrap(alias_cset_mod-1,0,13);
3754 }
3755 return D_O_K;
3756 }
3757
3758 int32_t onGotoPage()
3759 {
3760 if (draw_mode==dm_alias)
3761 {
3762 static const int PER_PAGE = 260;
3763 if(optional<int> v = call_get_num("Scroll to Alias Page", 0, MAXCOMBOALIASES/PER_PAGE-1, 0))
3764 combo_alistpos[current_comboalist] = *v*PER_PAGE;
3765 }
3766 else if (draw_mode==dm_cpool)
3767 {
3768 static const int PER_PAGE = 260;
3769 if(optional<int> v = call_get_num("Scroll to Combo Pool Page", 0, MAXCOMBOPOOLS/PER_PAGE-1, 0))
3770 combo_pool_listpos[current_cpoollist] = *v*PER_PAGE;
3771 }
3772 else if (draw_mode == dm_auto)
3773 {
3774 static const int PER_PAGE = 260;
3775 if(optional<int> v = call_get_num("Scroll to Auto Combo Page", 0, MAXAUTOCOMBOS/PER_PAGE-1, 0))
3776 combo_auto_listpos[current_cautolist] = *v*PER_PAGE;
3777 }
3778 else
3779 {
3780 static const int PER_PAGE = 256;
3781 if(optional<int> v = call_get_num("Scroll to Combo Page", 0, MAXCOMBOS/PER_PAGE-1, 0))
3782 First[current_combolist] = *v*PER_PAGE;
3783 }
3784
3785 return D_O_K;
3786 }
3787
3788 static char track_number_str_buf[MIDI_TRACK_BUFFER_SIZE] = {0};
3789 const char *tracknumlist(int32_t index, int32_t *list_size)
3790 {
3791 //memset(track_number_str_buf,0,50);
3792 if(index>=0)
3793 {
3794 bound(index,0,255);
3795 std::string name = zcmusic_get_track_name(zcmusic, index);
3796 sprintf(track_number_str_buf,"%02d %s",index+1, name.c_str());
3797 return track_number_str_buf;
3798 }
3799
3800 *list_size=zcmusic_get_tracks(zcmusic);
3801 return NULL;
3802 }
3803
3804 12 static ListData tracknum_list(tracknumlist, &font);
3805
3806 static DIALOG change_track_dlg[] =
3807 {
3808 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
3809 12 { jwin_win_proc, 60-12, 40, 200-16, 72, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Track", NULL, NULL },
3810 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
3811 12 { jwin_droplist_proc, 72-12, 60+4, 161, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &tracknum_list, NULL, NULL },
3812 12 { jwin_button_proc, 70, 87, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
3813 12 { jwin_button_proc, 150, 87, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
3814 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
3815 };
3816 // return list_dlg[2].d1;
3817
3818 int32_t changeTrack()
3819 {
3820 restore_mouse();
3821 change_track_dlg[0].dp2=get_zc_font(font_lfont);
3822 change_track_dlg[2].d1=gme_track;
3823
3824 large_dialog(change_track_dlg);
3825
3826 if(do_zqdialog(change_track_dlg,2)==3)
3827 {
3828 gme_track=change_track_dlg[2].d1;
3829 zcmusic_change_track(zcmusic, gme_track);
3830 }
3831
3832 return D_O_K;
3833 }
3834
3835 void set_media_tunes()
3836 {
3837 media_menu.select_uid(MENUID_MEDIA_TUNES, true);
3838 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, false);
3839 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3840 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3841
3842 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3843 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3844 }
3845
3846 int32_t playMusic()
3847 {
3848 char *ext;
3849 bool ismidi=false;
3850 char allmusic_types[256];
3851 sprintf(allmusic_types, "%s;mid", zcmusic_types);
3852
3853 if(prompt_for_existing_file_compat("Load Music",(char*)allmusic_types,NULL,midipath,false))
3854 {
3855 strcpy(midipath,temppath);
3856
3857 ext=get_extension(midipath);
3858
3859 if(
3860 (stricmp(ext,"ogg")==0)||
3861 (stricmp(ext,"mp3")==0)||
3862 (stricmp(ext,"it")==0)||
3863 (stricmp(ext,"xm")==0)||
3864 (stricmp(ext,"s3m")==0)||
3865 (stricmp(ext,"mod")==0)||
3866 (stricmp(ext,"spc")==0)||
3867 (stricmp(ext,"gym")==0)||
3868 (stricmp(ext,"nsf")==0)||
3869 (stricmp(ext,"gbs")==0)||
3870 (stricmp(ext,"vgm")==0)
3871 )
3872 {
3873 ismidi=false;
3874 }
3875 else if((stricmp(ext,"mid")==0))
3876 {
3877 ismidi=true;
3878 }
3879 else
3880 {
3881 return D_O_K;
3882 }
3883
3884 zc_stop_midi();
3885
3886 if(zcmusic != NULL)
3887 {
3888 zcmusic_stop(zcmusic);
3889 zcmusic_unload_file(zcmusic);
3890 zcmusic = NULL;
3891 zcmixer->newtrack = NULL;
3892 }
3893
3894 if(ismidi)
3895 {
3896 packfile_password("");
3897 if((song=load_midi(midipath))!=NULL)
3898 {
3899 if(zc_play_midi(song,true)==0)
3900 {
3901 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3902 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, true);
3903 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3904 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3905
3906 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3907 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3908 }
3909 }
3910 }
3911 else
3912 {
3913 gme_track=0;
3914 zcmusic = (ZCMUSIC*)zcmusic_load_file(midipath);
3915
3916 if(zcmusic!=NULL)
3917 {
3918 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3919 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, true);
3920 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3921 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3922
3923 bool distrack = zcmusic_get_tracks(zcmusic)<2;
3924 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, distrack);
3925 disable_hotkey(ZQKEY_CHANGE_TRACK, distrack);
3926
3927 zcmusic_play(zcmusic, midi_volume);
3928 }
3929 }
3930 }
3931
3932 return D_O_K;
3933 }
3934
3935 int32_t playZCForever()
3936 {
3937 stopMusic();
3938
3939 zcmusic = zcmusic_load_file("assets/zc/ZC_Forever_HD.mp3");
3940 if (zcmusic)
3941 {
3942 zcmusic_play(zcmusic, midi_volume);
3943 set_media_tunes();
3944 }
3945 return D_O_K;
3946 }
3947
3948 // It took awhile to get these values right, so no meddlin'!
3949 int32_t playTune1()
3950 {
3951 return playTune(0);
3952 }
3953 int32_t playTune2()
3954 {
3955 return playTune(81);
3956 }
3957 int32_t playTune3()
3958 {
3959 return playTune(233);
3960 }
3961 int32_t playTune4()
3962 {
3963 return playTune(553);
3964 }
3965 int32_t playTune5()
3966 {
3967 return playTune(814);
3968 }
3969 int32_t playTune6()
3970 {
3971 return playTune(985);
3972 }
3973 int32_t playTune7()
3974 {
3975 return playTune(1153);
3976 }
3977 int32_t playTune8()
3978 {
3979 return playTune(1333);
3980 }
3981 int32_t playTune9()
3982 {
3983 return playTune(1556);
3984 }
3985 int32_t playTune10()
3986 {
3987 return playTune(1801);
3988 }
3989 int32_t playTune11()
3990 {
3991 return playTune(2069);
3992 }
3993 int32_t playTune12()
3994 {
3995 return playTune(2189);
3996 }
3997 int32_t playTune13()
3998 {
3999 return playTune(2569);
4000 }
4001 int32_t playTune14()
4002 {
4003 return playTune(2753);
4004 }
4005 int32_t playTune15()
4006 {
4007 return playTune(2856);
4008 }
4009 int32_t playTune16()
4010 {
4011 return playTune(3042);
4012 }
4013 int32_t playTune17()
4014 {
4015 return playTune(3125);
4016 }
4017 int32_t playTune18()
4018 {
4019 return playTune(3217);
4020 }
4021 int32_t playTune19()
4022 {
4023 return playTune(3296);
4024 }
4025
4026 int32_t playTune(int32_t pos)
4027 {
4028 zc_stop_midi();
4029
4030 if(zcmusic != NULL)
4031 {
4032 zcmusic_stop(zcmusic);
4033 zcmusic_unload_file(zcmusic);
4034 zcmusic = NULL;
4035 zcmixer->newtrack = NULL;
4036 }
4037
4038 if(zc_play_midi(asset_tunes_midi,true)==0)
4039 {
4040 zc_midi_seek(pos);
4041 set_media_tunes();
4042 }
4043
4044 return D_O_K;
4045 }
4046
4047 int32_t stopMusic()
4048 {
4049 zc_stop_midi();
4050
4051 if(zcmusic != NULL)
4052 {
4053 zcmusic_stop(zcmusic);
4054 zcmusic_unload_file(zcmusic);
4055 zcmusic = NULL;
4056 zcmixer->newtrack = NULL;
4057 }
4058
4059 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
4060 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, false);
4061 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
4062 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
4063
4064 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
4065 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
4066 return D_O_K;
4067 }
4068
4069 static int32_t gamemisc1_list[] =
4070 {
4071 5,6,7,8,
4072 9,10,11,12,
4073
4074 37,38,39,40,
4075 41,42,43,44,
4076
4077 71,72,73,74,
4078 75,76,77,78,
4079
4080 -1
4081 };
4082
4083 static int32_t gamemisc2_list[] =
4084 {
4085 13,14,15,16,
4086 17,18,19,20,
4087
4088 45,46,47,48,
4089 49,50,51,52,
4090
4091 79,80,81,82,
4092 83,84,85,86,
4093
4094 -1
4095 };
4096
4097 static int32_t gamemisc3_list[] =
4098 {
4099 21,22,23,24,
4100 25,26,27,28,
4101
4102 53,54,55,56,
4103 57,58,59,60,
4104
4105 87,88,89,90,
4106 91,92,93,94,
4107
4108 -1
4109 };
4110
4111 static int32_t gamemisc4_list[] =
4112 {
4113 29,30,31,32,
4114 33,34,35,36,
4115
4116 61,62,63,64,
4117 65,66,67,68,
4118
4119 95,96,97,98,
4120 99,100,101,102,
4121
4122 -1
4123 };
4124
4125 static TABPANEL gamemisc_tabs[] =
4126 {
4127 // (text)
4128 { (char *)" Misc[0-7] ", D_SELECTED, gamemisc1_list, 0, NULL },
4129 { (char *)" Misc[8-15] ", 0, gamemisc2_list, 0, NULL },
4130 { (char *)" Misc[16-23] ", 0, gamemisc3_list, 0, NULL },
4131 { (char *)" Misc[24-31] ", 0, gamemisc4_list, 0, NULL },
4132 { NULL, 0, NULL, 0, NULL }
4133 };
4134
4135 //to do: Make string boxes larger, and split into two tabs.
4136 static DIALOG gamemiscarray_dlg[] =
4137 {
4138 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
4139
4140 { jwin_win_proc, 0, 10, 310, 224, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Game->Misc[]", NULL, NULL },
4141 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4142 { jwin_tab_proc, 3, 26, 304, 174, vc(14), vc(1), 0, 0, 1, 0, (void *) gamemisc_tabs, NULL, (void *)gamemiscarray_dlg },
4143 { d_dummy_proc, 240, 144, 40, 8, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
4144 { d_dummy_proc, 240, 144, 40, 8, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
4145
4146 //5
4147 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4148 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4149 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4150 //8
4151 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4152 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4153 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4154 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4155 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4156 //13
4157 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4158 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4159 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4160 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4161 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4162 //18
4163 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4164 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4165 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4166 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4167 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4168 //23
4169 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4170 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4171 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4172 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4173 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4174 //28
4175 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4176 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4177 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4178 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4179 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4180 //33
4181 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4182 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4183 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4184 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4185 //37
4186 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4187 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4188 //39
4189 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4190 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4191 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4192 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4193 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4194 //44
4195 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4196 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4197 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4198
4199 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4200 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4201 //49
4202 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4203 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4204 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4205 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4206 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4207 //54
4208 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4209 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4210 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4211 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4212 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4213 //59
4214 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4215 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4216 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4217 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4218 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4219 //64
4220 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4221 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4222 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4223 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4224 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4225 //69
4226 { jwin_button_proc, 70, 204, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
4227 { jwin_button_proc, 170, 204, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
4228
4229 //71
4230 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4231 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4232 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4233 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4234 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4235 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4236 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4237 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4238 //79
4239 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4240 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4241 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4242 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4243 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4244 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4245 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4246 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4247 //87
4248 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4249 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4250 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4251 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4252 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4253 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4254 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4255 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4256 //95
4257 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4258 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4259 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4260 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4261 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4262 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4263 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4264 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4265
4266 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
4267 };
4268
4269 // +----------+
4270 // | |
4271 // | View Pic |
4272 // | |
4273 // | |
4274 // | |
4275 // +----------+
4276
4277 BITMAP *pic=NULL;
4278 BITMAP *bmap=NULL;
4279 PALETTE picpal;
4280 PALETTE mappal;
4281 int32_t picx=0,picy=0,mapx=0,mapy=0,pblack,pwhite;
4282
4283 double picscale=1.0,mapscale=1.0;
4284 bool vp_showpal=true, vp_showsize=true, vp_center=true;
4285
4286 //INLINE int32_t pal_sum(RGB p) { return p.r + p.g + p.b; }
4287
4288 void get_bw(RGB *pal,int32_t &black,int32_t &white)
4289 {
4290 black=white=1;
4291
4292 for(int32_t i=1; i<256; i++)
4293 {
4294 if(pal_sum(pal[i])<pal_sum(pal[black]))
4295 black=i;
4296
4297 if(pal_sum(pal[i])>pal_sum(pal[white]))
4298 white=i;
4299 }
4300 }
4301
4302 void draw_bw_mouse(int32_t white, int32_t old_mouse, int32_t new_mouse)
4303 {
4304 blit(mouse_bmp[old_mouse][0],mouse_bmp[new_mouse][0],0,0,0,0,16,16);
4305
4306 for(int32_t y=0; y<16; y++)
4307 {
4308 for(int32_t x=0; x<16; x++)
4309 {
4310 if(getpixel(mouse_bmp[new_mouse][0],x,y)!=0)
4311 {
4312 putpixel(mouse_bmp[new_mouse][0],x,y,white);
4313 }
4314 }
4315 }
4316 }
4317
4318 int32_t load_the_pic(BITMAP **dst, PALETTE dstpal)
4319 {
4320 PALETTE temppal;
4321
4322 for(int32_t i=0; i<256; i++)
4323 {
4324 temppal[i]=dstpal[i];
4325 dstpal[i]=RAMpal[i];
4326 }
4327
4328 // set up the new palette
4329 for(int32_t i=0; i<64; i++)
4330 {
4331 dstpal[i].r = i;
4332 dstpal[i].g = i;
4333 dstpal[i].b = i;
4334 }
4335
4336 zc_set_palette(dstpal);
4337
4338 BITMAP *graypic = create_bitmap_ex(8,screen->w,screen->h);
4339 int32_t _w = screen->w-1;
4340 int32_t _h = screen->h-1;
4341
4342 // gray scale the current frame
4343 for(int32_t y=0; y<_h; y++)
4344 {
4345 for(int32_t x=0; x<_w; x++)
4346 {
4347 int32_t c = screen->line[y][x];
4348 int32_t gray = zc_min((temppal[c].r*42 + temppal[c].g*75 + temppal[c].b*14) >> 7, 63);
4349 graypic->line[y][x] = gray;
4350 }
4351 }
4352
4353 blit(graypic,screen,0,0,0,0,screen->w,screen->h);
4354 destroy_bitmap(graypic);
4355 #ifdef __GNUC__
4356 #pragma GCC diagnostic ignored "-Wformat-overflow"
4357 #endif
4358 char extbuf[2][80];
4359 memset(extbuf[0],0,80);
4360 memset(extbuf[1],0,80);
4361 sprintf(extbuf[0], "View Image (%s", snapshotformat_str[0][1]);
4362 strcpy(extbuf[1], snapshotformat_str[0][1]);
4363
4364 for(int32_t i=1; i<ssfmtMAX; ++i)
4365 {
4366 sprintf(extbuf[0], "%s, %s", extbuf[0], snapshotformat_str[i][1]);
4367 sprintf(extbuf[1], "%s;%s", extbuf[1], snapshotformat_str[i][1]);
4368 }
4369
4370 sprintf(extbuf[0], "%s)", extbuf[0]);
4371 #ifdef __GNUC__
4372 #pragma GCC diagnostic pop
4373 #endif
4374
4375 int32_t gotit = prompt_for_existing_file_compat(extbuf[0],extbuf[1],NULL,imagepath,true);
4376
4377 if(!gotit)
4378 {
4379 zc_set_palette(temppal);
4380 get_palette(dstpal);
4381 return 1;
4382 }
4383
4384 strcpy(imagepath,temppath);
4385
4386 if(*dst)
4387 {
4388 destroy_bitmap(*dst);
4389 }
4390
4391 for(int32_t i=0; i<256; i++)
4392 {
4393 dstpal[i].r = 0;
4394 dstpal[i].g = 0;
4395 dstpal[i].b = 0;
4396 }
4397
4398 *dst = load_bitmap(imagepath,picpal);
4399
4400 if(!*dst)
4401 {
4402 jwin_alert("Error","Error loading image:",imagepath,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4403 return 2;
4404 }
4405
4406 // get_bw(picpal,pblack,pwhite);
4407 // draw_bw_mouse(pwhite);
4408 // gui_bg_color = pblack;
4409 // gui_fg_color = pwhite;
4410
4411 if(vp_center)
4412 {
4413 picx=picy=0;
4414 }
4415 else
4416 {
4417 picx=(*dst)->w-zq_screen_w;
4418 picy=(*dst)->h-zq_screen_h;
4419 }
4420
4421 return 0;
4422 }
4423 int load_the_pic_new(BITMAP **dst, PALETTE dstpal)
4424 {
4425 #ifdef __GNUC__
4426 #pragma GCC diagnostic ignored "-Wformat-overflow"
4427 #endif
4428 char extbuf[2][80];
4429 memset(extbuf[0],0,80);
4430 memset(extbuf[1],0,80);
4431 sprintf(extbuf[0], "View Image (%s", snapshotformat_str[0][1]);
4432 strcpy(extbuf[1], snapshotformat_str[0][1]);
4433
4434 for(int32_t i=1; i<ssfmtMAX; ++i)
4435 {
4436 sprintf(extbuf[0], "%s, %s", extbuf[0], snapshotformat_str[i][1]);
4437 sprintf(extbuf[1], "%s;%s", extbuf[1], snapshotformat_str[i][1]);
4438 }
4439
4440 sprintf(extbuf[0], "%s)", extbuf[0]);
4441 #ifdef __GNUC__
4442 #pragma GCC diagnostic pop
4443 #endif
4444
4445 int32_t gotit = prompt_for_existing_file_compat(extbuf[0],extbuf[1],NULL,imagepath,true);
4446
4447 if(!gotit)
4448 return 1;
4449
4450 strcpy(imagepath,temppath);
4451
4452 if(*dst)
4453 destroy_bitmap(*dst);
4454
4455 for(int32_t i=0; i<256; i++)
4456 {
4457 dstpal[i].r = 0;
4458 dstpal[i].g = 0;
4459 dstpal[i].b = 0;
4460 }
4461
4462 *dst = load_bitmap(imagepath,dstpal);
4463
4464 if(!*dst)
4465 {
4466 jwin_alert("Error","Error loading image:",imagepath,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4467 return 2;
4468 }
4469
4470 if(vp_center)
4471 {
4472 picx=picy=0;
4473 }
4474 else
4475 {
4476 picx=(*dst)->w-zq_screen_w;
4477 picy=(*dst)->h-zq_screen_h;
4478 }
4479
4480 return 0;
4481 }
4482
4483 int32_t saveMapAsImage(ALLEGRO_BITMAP* bitmap)
4484 {
4485 char buf[200];
4486 int32_t num=0;
4487
4488 do
4489 {
4490 snprintf(buf, 200, "%szquest_map%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
4491 buf[199]='\0';
4492 }
4493 while(num<99999 && exists(buf));
4494
4495 if (!al_save_bitmap(buf, bitmap))
4496 InfoDialog("Error", "Failed to save map image").show();
4497
4498 return D_O_K;
4499 }
4500
4501 int32_t onViewPic()
4502 {
4503 return launchPicViewer(&pic,picpal,&picx,&picy,&picscale,false);
4504 }
4505
4506
4507 class MapViewRTI : public RenderTreeItem
4508 {
4509 public:
4510
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 MapViewRTI(): RenderTreeItem("map_view")
4511 12 {
4512 12 }
4513
4514 int bw, bh, sw, sh, flags;
4515
4516 private:
4517 void render(bool bitmap_resized)
4518 {
4519 MapCursor previous_cursor = Map.getCursor();
4520 Map.setViewSize(1);
4521
4522 BITMAP* bmap4_single = create_bitmap_ex(8,256,176);
4523 set_bitmap_create_flags(true);
4524 ALLEGRO_BITMAP* bmap5_single = al_create_bitmap(256,176);
4525 for(int32_t y=0; y<8; y++)
4526 {
4527 for(int32_t x=0; x<16; x++)
4528 {
4529 clear_bitmap(bmap4_single);
4530 Map.setCurrScr(y*16+x);
4531 Map.draw(bmap4_single, 0, 0, flags, -1, y*16+x, -1);
4532 stretch_blit(bmap4_single, bmap4_single, 0, 0, 0, 0, 256, 176, 256, 176);
4533 all_render_a5_bitmap(bmap4_single, bmap5_single);
4534 al_draw_scaled_bitmap(bmap5_single, 0, 0, 256, 176, sw * x, sh * y, sw, sh, 0);
4535 }
4536 }
4537
4538 Map.setCursor(previous_cursor);
4539 destroy_bitmap(bmap4_single);
4540 al_destroy_bitmap(bmap5_single);
4541 }
4542 };
4543 12 static MapViewRTI rti_map_view;
4544
4545 int32_t launchPicViewer(BITMAP **pictoview, PALETTE pal, int32_t *px2, int32_t *py2, double *scale2, bool isviewingmap, bool skipmenu)
4546 {
4547 restore_mouse();
4548 BITMAP *buf;
4549 bool done=false, redraw=true;
4550
4551 popup_zqdialog_start();
4552
4553 // Always call load_the_map() when viewing the map.
4554 if((!*pictoview || isviewingmap) && (isviewingmap ? load_the_map(skipmenu) : load_the_pic(pictoview,pal)))
4555 {
4556 zc_set_palette(RAMpal);
4557 popup_zqdialog_end();
4558 close_the_map();
4559 return D_O_K;
4560 }
4561
4562 get_bw(pal,pblack,pwhite);
4563
4564 int32_t oldfgcolor = gui_fg_color;
4565 int32_t oldbgcolor = gui_bg_color;
4566
4567 buf = create_bitmap_ex(8,zq_screen_w,zq_screen_h);
4568
4569 if(!buf)
4570 {
4571 jwin_alert("Error","Error creating temp bitmap",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4572 popup_zqdialog_end();
4573 close_the_map();
4574 return D_O_K;
4575 }
4576
4577 static LegacyBitmapRTI viewer_overlay_rti("viewer_overlay");
4578 viewer_overlay_rti.set_size(buf->w, buf->h);
4579 viewer_overlay_rti.a4_bitmap = buf;
4580 viewer_overlay_rti.transparency_index = 15;
4581 get_root_rti()->add_child(&viewer_overlay_rti);
4582
4583 zc_set_palette(pal);
4584
4585 if(isviewingmap)
4586 {
4587 set_center_root_rti(false);
4588
4589 int sw = rti_map_view.width / 16;
4590 int sh = rti_map_view.height / 8;
4591 int screen = Map.getCurrScr();
4592 if (screen >= 0x00 && screen <= 0x7F)
4593 {
4594 auto root_transform = get_root_rti()->get_transform();
4595 int dw = al_get_display_width(all_get_display()) / root_transform.xscale;
4596 int dh = al_get_display_height(all_get_display()) / root_transform.yscale;
4597 mapx = (-(screen % 16) * sw - sw/2 + dw/2);
4598 mapy = (-(screen / 16) * sh - sh/2 + dh/2);
4599 }
4600 }
4601
4602 do
4603 {
4604 int w, h;
4605 if (isviewingmap)
4606 {
4607 w = rti_map_view.width;
4608 h = rti_map_view.height;
4609 }
4610 else
4611 {
4612 w = (*pictoview)->w;
4613 h = (*pictoview)->h;
4614 }
4615
4616 if (isviewingmap)
4617 {
4618 float scale = *scale2;
4619 auto root_transform = get_root_rti()->get_transform();
4620 int dw = al_get_display_width(all_get_display()) / root_transform.xscale;
4621 int dh = al_get_display_height(all_get_display()) / root_transform.yscale;
4622 mapx = std::max(mapx, (int)(-w*scale + dw));
4623 mapy = std::max(mapy, (int)(-h*scale + dh));
4624 mapx = std::min(mapx, 0);
4625 mapy = std::min(mapy, 0);
4626 rti_map_view.set_transform({mapx, mapy, scale, scale});
4627 }
4628
4629 if(redraw)
4630 {
4631 clear_to_color(buf,15);
4632
4633 if (!isviewingmap)
4634 stretch_blit(*pictoview, buf, 0, 0, w, h,
4635 int32_t(zq_screen_w + (*px2 - w) * *scale2) / 2, int32_t(zq_screen_h + (*py2 - h) * *scale2) / 2,
4636 int32_t(w * *scale2), int32_t(h * *scale2));
4637
4638 if(vp_showpal)
4639 for(int32_t i=0; i<256; i++)
4640 rectfill(buf,((i&15)<<2)+zq_screen_w-64,((i>>4)<<2)+zq_screen_h-64,((i&15)<<2)+zq_screen_w-64+3,((i>>4)<<2)+zq_screen_h-64+3,i);
4641
4642 if(vp_showsize)
4643 {
4644 textprintf_ex(buf,font,0,zq_screen_h-8,pwhite,pblack,"%dx%d %.2f%%",w,h,*scale2*100.0);
4645 }
4646
4647 if (!isviewingmap)
4648 blit(buf,screen,0,0,0,0,zq_screen_w,zq_screen_h);
4649 redraw=false;
4650 }
4651
4652 custom_vsync();
4653
4654 int32_t step = 16;
4655
4656 if(*scale2 < 1.0)
4657 step = int32_t(4.0/ *scale2);
4658
4659 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
4660 step <<= 2;
4661
4662 if(CHECK_CTRL_CMD)
4663 step >>= 1;
4664
4665 if(key[KEY_UP])
4666 {
4667 *py2+=step;
4668 redraw=true;
4669 }
4670
4671 if(key[KEY_DOWN])
4672 {
4673 *py2-=step;
4674 redraw=true;
4675 }
4676
4677 if(key[KEY_LEFT])
4678 {
4679 *px2+=step;
4680 redraw=true;
4681 }
4682
4683 if(key[KEY_RIGHT])
4684 {
4685 *px2-=step;
4686 redraw=true;
4687 }
4688
4689 if(keypressed() && !redraw)
4690 switch(readkey()>>8)
4691 {
4692 case KEY_PGUP:
4693 *scale2*=0.95;
4694
4695 if(*scale2<0.1) *scale2=0.1;
4696
4697 redraw=true;
4698 break;
4699
4700 case KEY_PGDN:
4701 *scale2/=0.95;
4702
4703 if(*scale2>5.0) *scale2=5.0;
4704
4705 redraw=true;
4706 break;
4707
4708 case KEY_HOME:
4709 *scale2/=2.0;
4710
4711 if(*scale2<0.1) *scale2=0.1;
4712
4713 redraw=true;
4714 break;
4715
4716 case KEY_END:
4717 *scale2*=2.0;
4718
4719 if(*scale2>5.0) *scale2=5.0;
4720
4721 redraw=true;
4722 break;
4723
4724 case KEY_TILDE:
4725 *scale2=0.5;
4726 redraw=true;
4727 break;
4728
4729 case KEY_Z:
4730 *px2=w-zq_screen_w;
4731 *py2=h-zq_screen_h;
4732 vp_center=false;
4733 redraw=true;
4734 break;
4735
4736 case KEY_1:
4737 *scale2=1.0;
4738 redraw=true;
4739 break;
4740
4741 case KEY_2:
4742 *scale2=2.0;
4743 redraw=true;
4744 break;
4745
4746 case KEY_3:
4747 *scale2=3.0;
4748 redraw=true;
4749 break;
4750
4751 case KEY_4:
4752 *scale2=4.0;
4753 redraw=true;
4754 break;
4755
4756 case KEY_5:
4757 *scale2=5.0;
4758 redraw=true;
4759 break;
4760
4761 case KEY_C:
4762 *px2=*py2=0;
4763 redraw=vp_center=true;
4764 break;
4765
4766 case KEY_S:
4767 vp_showsize = !vp_showsize;
4768 redraw=true;
4769 break;
4770
4771 case KEY_D:
4772 vp_showpal = !vp_showpal;
4773 redraw=true;
4774 break;
4775
4776 case KEY_P:
4777 if(isviewingmap) break;
4778
4779 case KEY_ESC:
4780 done=true;
4781 break;
4782
4783 case KEY_SPACE:
4784 close_the_map();
4785 // TODO: why is `load_the_map` rendering a black dialog?
4786 if(isviewingmap ? load_the_map(skipmenu) : load_the_pic(pictoview,pal)==2)
4787 {
4788 done=true;
4789 }
4790 else
4791 {
4792 redraw=true;
4793 gui_bg_color = pblack;
4794 gui_fg_color = pwhite;
4795 *scale2=1.0;
4796 zc_set_palette(pal);
4797 }
4798
4799 get_bw(pal,pblack,pwhite);
4800 break;
4801 }
4802 }
4803 while(!done);
4804
4805 destroy_bitmap(buf);
4806 zc_set_palette(RAMpal);
4807 gui_fg_color = oldfgcolor;
4808 gui_bg_color = oldbgcolor;
4809
4810 popup_zqdialog_end();
4811 position_mouse_z(0);
4812 viewer_overlay_rti.remove();
4813 set_center_root_rti(true);
4814 close_the_map();
4815 return D_O_K;
4816 }
4817
4818 static DIALOG loadmap_dlg[] =
4819 {
4820 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
4821 { jwin_win_proc, 0, 0, 225, 143, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "View Map", NULL, NULL },
4822 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4823 { jwin_text_proc, 32, 26, 96, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Resolution", NULL, NULL },
4824 // 3
4825 { jwin_radio_proc, 16, 36, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "1/4 - 1024x352", NULL, NULL },
4826 { jwin_radio_proc, 16, 46, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "1/2 - 2048x704", NULL, NULL },
4827 { jwin_radio_proc, 16, 56, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Full - 4096x1408", NULL, NULL },
4828 { jwin_text_proc, 144, 26, 97, 9, vc(11), vc(1), 0, 0, 0, 0, (void *) "Options", NULL, NULL },
4829 // 7
4830 { jwin_check_proc, 144, 36, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Solidity", NULL, NULL },
4831 { jwin_check_proc, 144, 46, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Flags", NULL, NULL },
4832 { jwin_check_proc, 144, 56, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Dark", NULL, NULL },
4833 { jwin_check_proc, 144, 66, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Items", NULL, NULL },
4834 // 11
4835 { jwin_button_proc, 42, 110, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
4836 { jwin_button_proc, 122, 110, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
4837 { jwin_check_proc, 16, 88, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Save to Image", NULL, NULL },
4838 // 14
4839 { jwin_radio_proc, 16, 66, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void*)"2x - 8192x2816", NULL, NULL },
4840 { jwin_radio_proc, 16, 76, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void*)"4x - 16384x5632", NULL, NULL },
4841 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
4842 };
4843
4844 int32_t load_the_map(bool skipmenu)
4845 {
4846 static int32_t res = 0;
4847 static int32_t flags = cDEBUG;
4848
4849 loadmap_dlg[0].dp2 = get_zc_font(font_lfont);
4850 loadmap_dlg[3].flags = (res==2) ? D_SELECTED : 0;
4851 loadmap_dlg[4].flags = (res==1) ? D_SELECTED : 0;
4852 loadmap_dlg[5].flags = (res==0) ? D_SELECTED : 0;
4853 loadmap_dlg[7].flags = (flags&cWALK) ? D_SELECTED : 0;
4854 loadmap_dlg[8].flags = (flags&cFLAGS) ? D_SELECTED : 0;
4855 loadmap_dlg[9].flags = (flags&cNODARK) ? 0 : D_SELECTED;
4856 loadmap_dlg[10].flags = (flags&cNOITEM) ? 0 : D_SELECTED;
4857 loadmap_dlg[13].flags = 0;
4858 loadmap_dlg[14].flags = (res==3) ? D_SELECTED : 0;
4859 loadmap_dlg[15].flags = (res==4) ? D_SELECTED : 0;
4860
4861 if(!skipmenu)
4862 {
4863 large_dialog(loadmap_dlg);
4864
4865 if (do_zqdialog(loadmap_dlg, 11) != 11)
4866 {
4867 return 1;
4868 }
4869
4870 flags = cDEBUG;
4871
4872 if(loadmap_dlg[3].flags&D_SELECTED) res=2;
4873
4874 if(loadmap_dlg[4].flags&D_SELECTED) res=1;
4875
4876 if(loadmap_dlg[5].flags&D_SELECTED) res=0;
4877
4878 if(loadmap_dlg[7].flags&D_SELECTED) flags|=cWALK;
4879
4880 if(loadmap_dlg[8].flags&D_SELECTED) flags|=cFLAGS;
4881
4882 if(!(loadmap_dlg[9].flags&D_SELECTED)) flags|=cNODARK;
4883
4884 if(!(loadmap_dlg[10].flags&D_SELECTED)) flags|=cNOITEM;
4885
4886 if(loadmap_dlg[14].flags&D_SELECTED) res=3;
4887
4888 if(loadmap_dlg[15].flags&D_SELECTED) res=4;
4889 }
4890
4891 int32_t bw = (256*16)>>res;
4892 int32_t bh = (176*8)>>res;
4893 int32_t sw = 256>>res;
4894 int32_t sh = 176>>res;
4895 if(res>2)
4896 {
4897 bw = (256*16)<<(res-2);
4898 bh = (176*8)<<(res-2);
4899 sw = 256<<(res-2);
4900 sh = 176<<(res-2);
4901 }
4902
4903 rti_map_view.flags = flags;
4904 rti_map_view.bw = bw;
4905 rti_map_view.bh = bh;
4906 rti_map_view.sw = sw;
4907 rti_map_view.sh = sh;
4908 rti_map_view.set_size(bw, bh);
4909 rti_map_view.dirty = true;
4910 get_root_rti()->add_child(&rti_map_view);
4911 render_zq();
4912
4913 vp_showpal = false;
4914 get_bw(picpal,pblack,pwhite);
4915 mapx = mapy = 0;
4916 mapscale = 1;
4917 imagepath[0] = 0;
4918
4919 if(loadmap_dlg[13].flags & D_SELECTED) saveMapAsImage(rti_map_view.bitmap);
4920
4921 memcpy(mappal,RAMpal,sizeof(RAMpal));
4922
4923 return 0;
4924 }
4925
4926 void close_the_map()
4927 {
4928 rti_map_view.remove();
4929 }
4930
4931 int32_t onViewMap()
4932 {
4933 return onViewMapEx(false);
4934 }
4935 int32_t onViewMapEx(bool skipmenu)
4936 {
4937 int32_t temp_aligns=ShowMisalignments;
4938 ShowMisalignments=0;
4939 //if(load_the_map()==0)
4940 //{
4941 launchPicViewer(&bmap,mappal,&mapx, &mapy, &mapscale,true,skipmenu);
4942 //}
4943 ShowMisalignments=temp_aligns;
4944 return D_O_K;
4945 }
4946
4947 static const char *mazedirstr[4] = {"North","South","West","East"};
4948 char _pathstr[40]="North,North,North,North";
4949
4950 char *pathstr(byte path[])
4951 {
4952 sprintf(_pathstr,"%s,%s,%s,%s",mazedirstr[path[0]],mazedirstr[path[1]],
4953 mazedirstr[path[2]],mazedirstr[path[3]]);
4954 return _pathstr;
4955 }
4956
4957 char _ticksstr[32]="99.99 seconds";
4958
4959 char *ticksstr(int32_t tics)
4960 {
4961 int32_t mins=tics/(60*60);
4962 tics=tics-(mins*60*60);
4963 int32_t secs=tics/60;
4964 tics=tics-(secs*60);
4965 tics=tics*100/60;
4966
4967 if(mins>0)
4968 {
4969 sprintf(_ticksstr,"%d:%02d.%02d",mins, secs, tics);
4970 }
4971 else
4972 {
4973 sprintf(_ticksstr,"%d.%02d seconds",secs, tics);
4974 }
4975
4976 return _ticksstr;
4977 }
4978
4979 ZC_FORMAT_PRINTF(7, 8)
4980 void textprintf_disabled(BITMAP *bmp, AL_CONST FONT *f, int32_t x, int32_t y, int32_t color_hl, int32_t color_sh, AL_CONST char *format, ...)
4981 {
4982 char buf[512];
4983 va_list ap;
4984 ASSERT(bmp);
4985 ASSERT(f);
4986 ASSERT(format);
4987
4988 va_start(ap, format);
4989 uvszprintf(buf, sizeof(buf), format, ap);
4990 va_end(ap);
4991
4992
4993 textout_ex(bmp, f, buf, x+1, y+1, color_hl, -1);
4994
4995 textout_ex(bmp, f, buf, x, y, color_sh, -1);
4996 }
4997
4998 ZC_FORMAT_PRINTF(7, 8)
4999 void textprintf_centre_disabled(BITMAP *bmp, AL_CONST FONT *f, int32_t x, int32_t y, int32_t color_hl, int32_t color_sh, AL_CONST char *format, ...)
5000 {
5001 char buf[512];
5002 va_list ap;
5003 ASSERT(bmp);
5004 ASSERT(f);
5005 ASSERT(format);
5006
5007 va_start(ap, format);
5008 uvszprintf(buf, sizeof(buf), format, ap);
5009 va_end(ap);
5010
5011 textout_centre_ex(bmp, f, buf, x+1, y+1, color_hl, -1);
5012 textout_centre_ex(bmp, f, buf, x, y, color_sh, -1);
5013 }
5014
5015 void draw_sqr_frame(size_and_pos const& sqr)
5016 {
5017 jwin_draw_frame(menu1,sqr.x,sqr.y,sqr.tw(),sqr.th(),FR_DEEP);
5018 }
5019 void draw_sqr_icon(size_and_pos const& sqr, BITMAP* icon)
5020 {
5021 stretch_blit(icon, menu1, 0, 0, 16, 16, sqr.x+2, sqr.y+2, sqr.tw()-4, sqr.th()-4);
5022 }
5023 void draw_sqr_nums(size_and_pos const& sqr, FONT* f, bool center, int num)
5024 {
5025 if(center)
5026 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_single.x,sqr.y+txtoffs_single.y,jwin_pal[jcBOXFG],-1,"%d",num);
5027 else
5028 textprintf_ex(menu1,f,sqr.x+txtoffs_single.x,sqr.y+txtoffs_single.y,jwin_pal[jcBOXFG],-1,"%d",num);
5029 }
5030 void draw_sqr_nums(size_and_pos const& sqr, FONT* f, bool center, int num1, int num2)
5031 {
5032 if(center)
5033 {
5034 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_double_1.x,sqr.y+txtoffs_double_1.y,jwin_pal[jcBOXFG],-1,"%d",num1);
5035 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_double_2.x,sqr.y+txtoffs_double_2.y,jwin_pal[jcBOXFG],-1,"%d",num2);
5036 }
5037 else
5038 {
5039 textprintf_ex(menu1,f,sqr.x+txtoffs_double_1.x,sqr.y+txtoffs_double_1.y,jwin_pal[jcBOXFG],-1,"%d",num1);
5040 textprintf_ex(menu1,f,sqr.x+txtoffs_double_2.x,sqr.y+txtoffs_double_2.y,jwin_pal[jcBOXFG],-1,"%d",num2);
5041 }
5042 }
5043 void draw_sqr_btn(size_and_pos const& sqr, const char* txt, int flags, FONT* f = nullptr)
5044 {
5045 if(sqr.x < 0) return;
5046 FONT* tfont = font;
5047 if(f)
5048 font = f;
5049 draw_text_button(menu1, sqr.x, sqr.y, sqr.tw(), sqr.th(), txt, 0, 0, flags, true);
5050 font = tfont;
5051 }
5052 void draw_sqr_btn(size_and_pos const& sqr, int icon, int flags, FONT* f = nullptr)
5053 {
5054 if(sqr.x < 0) return;
5055 FONT* tfont = font;
5056 if(f)
5057 font = f;
5058 draw_icon_button(menu1, sqr.x, sqr.y, sqr.tw(), sqr.th(), icon, 0, 0, flags, true);
5059 font = tfont;
5060 }
5061
5062 void drawpanel()
5063 {
5064 mapscr *scr=Map.CurrScr();
5065 int32_t NextCombo = combobuf[Combo].nextcombo;
5066 int32_t NextCSet = combobuf[Combo].nextcset;
5067 if(combobuf[Combo].animflags & AF_CYCLEUNDERCOMBO)
5068 {
5069 NextCombo = scr->undercombo;
5070 NextCSet = scr->undercset;
5071 }
5072 if(combobuf[Combo].animflags & AF_CYCLENOCSET)
5073 NextCSet = CSet;
5074
5075 FONT* tfont = font;
5076 if(prv_mode)
5077 {
5078 jwin_draw_frame(menu1,0,preview_panel.y,preview_panel.x+preview_panel.w, preview_panel.h, FR_WIN);
5079 rectfill(menu1,preview_panel.x,preview_panel.y+2,preview_panel.x+preview_panel.w-3,preview_panel.y+preview_panel.h-3,jwin_pal[jcBOX]);
5080 }
5081 else
5082 {
5083 auto& sqr = main_panel;
5084 rectfill(menu1,sqr.x,sqr.y,sqr.x+sqr.w-1,sqr.y+sqr.h-1, jwin_pal[jcBOX]);
5085 refresh(rSCRMAP);
5086 jwin_draw_frame(menu1,sqr.x,sqr.y,sqr.w,sqr.h, FR_WIN);
5087
5088 font = get_custom_font(CFONT_GUI);
5089 draw_sqr_btn(squarepanel_swap_btn, "SWP", 0);
5090 if(compact_square_panels)
5091 {
5092 textprintf_centre_ex(menu1,font,squarepanel_up_btn.cx(),squarepanel_up_btn.y-text_height(font)-2,jwin_pal[jcBOXFG],-1,"%d",compact_active_panel);
5093 draw_sqr_btn(squarepanel_up_btn, BTNICON_ARROW_UP, 0);
5094 draw_sqr_btn(squarepanel_down_btn, BTNICON_ARROW_DOWN, 0);
5095 }
5096 font = tfont;
5097
5098 FONT* sqr_text_font = (is_compact && compact_square_panels) ? get_custom_font(CFONT_GUI) : font;
5099 //Item:
5100 if(itemsqr_pos.x > -1)
5101 {
5102 draw_sqr_frame(itemsqr_pos);
5103 if(scr->hasitem)
5104 {
5105 rectfill(menu1,itemsqr_pos.x+2,itemsqr_pos.y+2,itemsqr_pos.x+itemsqr_pos.tw()-3,itemsqr_pos.y+itemsqr_pos.th()-3,0);
5106 overtile16_scale(menu1, itemsbuf[scr->item].tile,itemsqr_pos.x+2,itemsqr_pos.y+2,itemsbuf[scr->item].csets&15,0,itemsqr_pos.tw()-4,itemsqr_pos.th()-4);
5107 }
5108 else draw_sqr_icon(itemsqr_pos, icon_bmp[0][coord_frame]);
5109 draw_sqr_nums(itemsqr_pos, sqr_text_font, panel_align == 1, scr->itemx, scr->itemy);
5110 }
5111 //Flag:
5112 if(flagsqr_pos.x > -1)
5113 {
5114 draw_sqr_frame(flagsqr_pos);
5115 draw_sqr_icon(flagsqr_pos,flag_bmp[Flag%16][coord_frame]);
5116 draw_sqr_nums(flagsqr_pos, sqr_text_font, panel_align == 1, Flag);
5117 }
5118
5119 //Stairs:
5120 if(stairsqr_pos.x > -1)
5121 {
5122 draw_sqr_frame(stairsqr_pos);
5123 draw_sqr_icon(stairsqr_pos,icon_bmp[1][coord_frame]);
5124 draw_sqr_nums(stairsqr_pos, sqr_text_font, panel_align == 1, scr->stairx, scr->stairy);
5125 }
5126
5127 //Green arrival square:
5128 bool disabled_arrival = get_qr(qr_NOARRIVALPOINT);
5129 if(warparrival_pos.x > -1)
5130 {
5131 draw_sqr_frame(warparrival_pos);
5132 BITMAP* icon = icon_bmp[2][coord_frame];
5133 if(disabled_arrival)
5134 {
5135 icon = create_bitmap_ex(8,16,16);
5136 blit(icon_bmp[2][0], icon, 0, 0, 0, 0, 16, 16);
5137 replColor(icon, 0xE7, 0xEA, 0xEA, false);
5138 replColor(icon, 0xE8, 0xE2, 0xE2, false);
5139 }
5140
5141 draw_sqr_icon(warparrival_pos, icon);
5142 draw_sqr_nums(warparrival_pos, sqr_text_font, panel_align == 1, scr->warparrivalx, scr->warparrivaly);
5143
5144 if(disabled_arrival)
5145 destroy_bitmap(icon);
5146 }
5147
5148 //Blue return squares:
5149 for(int32_t i=0; i<4; i++)
5150 {
5151 if(warpret_pos[i].x < 0) continue;
5152 draw_sqr_frame(warpret_pos[i]);
5153 draw_sqr_icon(warpret_pos[i], icon_bmp[ICON_BMP_RETURN_A+i][coord_frame]);
5154 draw_sqr_nums(warpret_pos[i], sqr_text_font, panel_align == 1, scr->warpreturnx[i], scr->warpreturny[i]);
5155 }
5156
5157 // Enemies
5158 auto& ep = enemy_prev_pos;
5159 if(ep.x > -1)
5160 {
5161 if(ep.fw > -1)
5162 {
5163 rectfill(menu1, ep.x, ep.y, ep.x+ep.tw()-1,ep.y+ep.th()-1,vc(0));
5164 rectfill(menu1, ep.x+ep.fw, ep.y+ep.fh, ep.x+ep.tw()-1, ep.y+ep.th()-1, jwin_pal[jcBOX]);
5165 jwin_draw_frag_frame(menu1, ep.x, ep.y, ep.tw(), ep.th(), ep.fw, ep.fh, FR_DEEP);
5166 }
5167 else
5168 {
5169 rectfill(menu1, ep.x, ep.y, ep.x+ep.tw()-1,ep.y+ep.th()-1,vc(0));
5170 draw_sqr_frame(ep);
5171 }
5172 for(int32_t i=0; i< 10 && Map.CurrScr()->enemy[i]!=0; i++)
5173 {
5174 int32_t id = Map.CurrScr()->enemy[i];
5175 int32_t tile = get_qr(qr_NEWENEMYTILES) ? guysbuf[id].e_tile : guysbuf[id].tile;
5176 int32_t cset = guysbuf[id].cset;
5177 auto& sqr = ep.subsquare(i);
5178 if(tile)
5179 overtile16_scale(menu1, tile+efrontfacingtile(id),sqr.x,sqr.y,cset,0,sqr.tw(),sqr.th());
5180 }
5181 }
5182 }
5183 font = tfont;
5184 }
5185
5186 void show_screen_error(const char *str, int32_t i, int32_t c)
5187 {
5188 rectfill(menu1, screrrorpos.x-text_length(get_zc_font(font_lfont_l),str),screrrorpos.y-(i*16),screrrorpos.x,screrrorpos.y-((i-1)*16)-4,vc(0));
5189 textout_shadowed_ex(menu1,get_zc_font(font_lfont_l), str,screrrorpos.x-text_length(get_zc_font(font_lfont_l),str),screrrorpos.y-(i*16),c,vc(0),-1);
5190 }
5191
5192 void tile_warp_notification(int32_t which, char *buf)
5193 {
5194 char letter = 'A'+which;
5195
5196 switch(Map.CurrScr()->tilewarptype[which])
5197 {
5198 case wtCAVE:
5199 sprintf(buf,"Tile Warp %c: Cave/Item Cellar",letter);
5200 break;
5201
5202 default:
5203 {
5204 char buf2[30];
5205
5206 if(strlen(DMaps[Map.CurrScr()->tilewarpdmap[which]].name)==0)
5207 {
5208 sprintf(buf2,"%d",Map.CurrScr()->tilewarpdmap[which]);
5209 }
5210 else
5211 sprintf(buf2,"%d-%s",Map.CurrScr()->tilewarpdmap[which],DMaps[Map.CurrScr()->tilewarpdmap[which]].name);
5212
5213 sprintf(buf,"Tile Warp %c: %s, %02X", letter, buf2, Map.CurrScr()->tilewarpscr[which]);
5214 break;
5215 }
5216
5217 case wtNOWARP:
5218 sprintf(buf,"Tile Warp %c: Cancel Warp", letter);
5219 break;
5220 }
5221 }
5222
5223 void side_warp_notification(int32_t which, int32_t dir, char *buf)
5224 {
5225 char letter = 'A'+which;
5226 char buf3[16];
5227
5228 if(dir==0 && Map.CurrScr()->timedwarptics)
5229 sprintf(buf3,"%s, Timed",mazedirstr[dir]);
5230 else if(dir==4)
5231 sprintf(buf3,"Timed");
5232 else
5233 strcpy(buf3, mazedirstr[dir]);
5234
5235 switch(Map.CurrScr()->sidewarptype[which])
5236 {
5237 case wtCAVE:
5238 sprintf(buf,"Side Warp %c (%s): Cave/Item Cellar",letter, buf3);
5239 break;
5240
5241 default:
5242 {
5243 // Destination DMap name
5244 if(strlen(DMaps[Map.CurrScr()->sidewarpdmap[which]].name)==0)
5245 {
5246 sprintf(buf,"Side Warp %c (%s): %d, %02X", letter, buf3, Map.CurrScr()->sidewarpdmap[which], Map.CurrScr()->sidewarpscr[which]);
5247 }
5248 else
5249 sprintf(buf,"Side Warp %c (%s): %d-%s, %02X", letter, buf3, Map.CurrScr()->sidewarpdmap[which],DMaps[Map.CurrScr()->sidewarpdmap[which]].name, Map.CurrScr()->sidewarpscr[which]);
5250
5251 break;
5252 }
5253
5254 case wtNOWARP:
5255 sprintf(buf,"Side Warp %c (%s): Cancel Warp", letter, buf3);
5256 break;
5257 }
5258 }
5259
5260 static bool arrowcursor = true; // Used by combo aliases and Combo Brush cursors. -L
5261
5262 void xout(BITMAP* dest, int x, int y, int x2, int y2, int c, int bgc = -1)
5263 {
5264 //BG Fill
5265 if(bgc > -1)
5266 rectfill(dest, x, y, x2, y2, bgc);
5267 ++x; ++y; --x2; --y2;
5268 //Border
5269 safe_rect(dest, x, y, x2, y2, c);
5270 //line(dest, x, y, x2, y, c);
5271 //line(dest, x, y, x, y2, c);
5272 //X
5273 line(dest, x, y, x2, y2, c);
5274 line(dest, x, y2, x2, y, c);
5275 }
5276
5277 void put_autocombo_engravings(BITMAP* dest, combo_auto const& ca, bool selected, int32_t x, int32_t y, int32_t scale)
5278 {
5279 if (!ca.valid())
5280 {
5281 if (ca.getDisplay() > 0)
5282 put_engraving(dest, x, y, 15, scale);
5283 }
5284 else
5285 {
5286 if (ca.getType() == AUTOCOMBO_Z4 || ca.getType() == AUTOCOMBO_DOR)
5287 {
5288 byte hei = vbound(ca.getArg() + 1, 1, 9);
5289 if (selected)
5290 hei = vbound(cauto_height, 1, 9);
5291 put_engraving(dest, x, y, 15 - hei, scale);
5292 }
5293 }
5294 }
5295
5296 void draw_screenunit_map_screen(VisibleScreen visible_screen)
5297 {
5298 int num_screens_to_draw = Map.getViewSize();
5299 int screen = visible_screen.screen;
5300 int xoff = visible_screen.xoff;
5301 int yoff = visible_screen.yoff;
5302
5303 mapscr* scr = visible_screen.scr;
5304 if (!layers_valid(scr))
5305 fix_layers(scr, true);
5306
5307 clear_to_color(mapscreenbmp, jwin_pal[jcBOX]);
5308 if (LayerDitherBG > -1)
5309 {
5310 if (LayerDitherSz > 0)
5311 ditherblit(mapscreenbmp, nullptr, vc(LayerDitherBG), dithChecker, LayerDitherSz);
5312 else
5313 clear_to_color(mapscreenbmp, vc(LayerDitherBG));
5314 }
5315
5316 int view_scr_x = Map.getViewScr() % 16;
5317 int view_scr_y = Map.getViewScr() / 16;
5318 int scr_x = screen % 16;
5319 int scr_y = screen / 16;
5320 int edge_xoff = 0, edge_yoff = 0;
5321 if(showedges)
5322 {
5323 if (scr_x == view_scr_x)
5324 edge_xoff = 16;
5325 else
5326 xoff -= 16;
5327
5328 if (scr_y == view_scr_y)
5329 edge_yoff = 16;
5330 else
5331 yoff -= 16;
5332 }
5333
5334 combotile_add_x = mapscreen_x + xoff;
5335 combotile_add_y = mapscreen_y + yoff;
5336 combotile_mul_x = mapscreen_single_scale;
5337 combotile_mul_y = mapscreen_single_scale;
5338 Map.draw(mapscreenbmp, scr_x == view_scr_x && showedges ? 16 : 0, scr_y == view_scr_y && showedges ? 16 : 0, Flags, Map.getCurrMap(), screen, ActiveLayerHighlight ? CurrentLayer : -1);
5339 combotile_add_x = 0;
5340 combotile_add_y = 0;
5341 combotile_mul_x = 1;
5342 combotile_mul_y = 1;
5343
5344 // TODO: should be better to move this out of draw_screenunit_map_screen.
5345 if (showedges && screen < 128)
5346 {
5347 bool peek_above = scr_y == view_scr_y;
5348 bool peek_below = scr_y == view_scr_y + num_screens_to_draw - 1;
5349 bool peek_left = scr_x == view_scr_x;
5350 bool peek_right = scr_x == view_scr_x + num_screens_to_draw - 1;
5351
5352 int right_col = 272 - (num_screens_to_draw > 1 ? 16 : 0);
5353 int bottom_row = 192 - (num_screens_to_draw > 1 ? 16 : 0);
5354
5355 //not the first row of screens
5356 if (peek_above)
5357 {
5358 if(screen>15 && !NoScreenPreview)
5359 {
5360 Map.drawrow(mapscreenbmp, edge_xoff, 0, Flags, 160, -1, screen-16);
5361 }
5362 else
5363 {
5364 Map.drawstaticrow(mapscreenbmp, edge_xoff, 0);
5365 }
5366 }
5367
5368 //not the last row of screens
5369 if (peek_below)
5370 {
5371 if(screen + 16 < 0x80 && !NoScreenPreview)
5372 {
5373 Map.drawrow(mapscreenbmp, edge_xoff, bottom_row, Flags, 0, -1, screen+16);
5374 }
5375 else
5376 {
5377 Map.drawstaticrow(mapscreenbmp, edge_xoff, bottom_row);
5378 }
5379 }
5380
5381 //not the first column of screens
5382 if (peek_left)
5383 {
5384 if(screen&0x0F && !NoScreenPreview)
5385 {
5386 Map.drawcolumn(mapscreenbmp, 0, edge_yoff, Flags, 15, -1, screen-1);
5387 }
5388 else
5389 {
5390 Map.drawstaticcolumn(mapscreenbmp, 0, edge_yoff);
5391 }
5392 }
5393
5394 //not the last column of screens
5395 if (peek_right)
5396 {
5397 if((screen&0x0F)<15 && !NoScreenPreview)
5398 {
5399 Map.drawcolumn(mapscreenbmp, right_col, edge_yoff, Flags, 0, -1, screen+1);
5400 }
5401 else
5402 {
5403 Map.drawstaticcolumn(mapscreenbmp, right_col, edge_yoff);
5404 }
5405 }
5406
5407 //not the first row or first column of screens
5408 if (peek_above && peek_left)
5409 {
5410 if((screen>15)&&(screen&0x0F) && !NoScreenPreview)
5411 {
5412 Map.drawblock(mapscreenbmp, 0, 0, Flags, 175, -1, screen-17);
5413 }
5414 else
5415 {
5416 Map.drawstaticblock(mapscreenbmp, 0, 0);
5417 }
5418 }
5419
5420 //not the first row or last column of screens
5421 if (peek_above && peek_right)
5422 {
5423 if((screen>15)&&((screen&0x0F)<15) && !NoScreenPreview)
5424 {
5425 Map.drawblock(mapscreenbmp, right_col, 0, Flags, 160, -1, screen-15);
5426 }
5427 else
5428 {
5429 Map.drawstaticblock(mapscreenbmp, right_col, 0);
5430 }
5431 }
5432
5433 //not the last row or first column of screens
5434 if (peek_below && peek_left)
5435 {
5436 if((screen<112)&&(screen&0x0F) && !NoScreenPreview)
5437 {
5438 Map.drawblock(mapscreenbmp, 0, bottom_row, Flags, 15, -1, screen+15);
5439 }
5440 else
5441 {
5442 Map.drawstaticblock(mapscreenbmp, 0, bottom_row);
5443 }
5444 }
5445
5446 //not the last row or last column of screens
5447 if (peek_below && peek_right)
5448 {
5449 if((screen<112)&&((screen&0x0F)<15) && !NoScreenPreview)
5450 {
5451 Map.drawblock(mapscreenbmp, right_col, bottom_row, Flags, 0, -1, screen+17);
5452 }
5453 else
5454 {
5455 Map.drawstaticblock(mapscreenbmp, right_col, bottom_row);
5456 }
5457 }
5458 }
5459
5460 if (ShowSquares && Map.getViewSize() < 4)
5461 {
5462 if(scr->stairx || scr->stairy)
5463 {
5464 int32_t x1 = scr->stairx+edge_xoff;
5465 int32_t y1 = scr->stairy+edge_yoff;
5466 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(14));
5467 }
5468
5469 if(scr->warparrivalx || scr->warparrivaly)
5470 {
5471 int32_t x1 = scr->warparrivalx +edge_xoff;
5472 int32_t y1 = scr->warparrivaly +edge_yoff;
5473 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(10));
5474 }
5475
5476 for(int32_t i=0; i<4; i++) if(scr->warpreturnx[i] || scr->warpreturny[i])
5477 {
5478 int32_t x1 = scr->warpreturnx[i]+edge_xoff;
5479 int32_t y1 = scr->warpreturny[i]+edge_yoff;
5480 int32_t clr = vc(9);
5481
5482 if(FlashWarpSquare==i)
5483 {
5484 if(!FlashWarpClk)
5485 FlashWarpSquare=-1;
5486 else if(!(--FlashWarpClk%3))
5487 clr = vc(15);
5488 }
5489
5490 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,clr);
5491 }
5492 }
5493
5494 if(ShowFFCs)
5495 {
5496 mapscr* ffscr = prv_mode ? Map.get_prvscr() : scr;
5497 int num_ffcs = ffscr->numFFC();
5498 for(int32_t i=num_ffcs-1; i>=0; i--)
5499 {
5500 ffcdata& ff = ffscr->ffcs[i];
5501 if(ff.data !=0 && (ff.layer >= CurrentLayer || (ff.flags&ffc_overlay)))
5502 {
5503 auto x = ff.x+edge_xoff;
5504 auto y = ff.y+edge_yoff;
5505 safe_rect(mapscreenbmp, x+0, y+0, x+ff.txsz*16-1, y+ff.tysz*16-1, vc(12));
5506 }
5507 }
5508 }
5509
5510 if(!(Flags&cDEBUG) && pixeldb==1)
5511 {
5512 for(int32_t j=168; j<176; j++)
5513 {
5514 for(int32_t i=0; i<256; i++)
5515 {
5516 if(((i^j)&1)==0)
5517 {
5518 putpixel(mapscreenbmp,edge_xoff+i,
5519 edge_yoff+j,vc(blackout_color));
5520 }
5521 }
5522 }
5523 }
5524
5525 int w = mapscreenbmp->w * mapscreen_single_scale;
5526 int h = mapscreenbmp->h * mapscreen_single_scale;
5527 stretch_blit(mapscreenbmp, menu1, 0, 0, mapscreenbmp->w, mapscreenbmp->h, mapscreen_x + xoff, mapscreen_y + yoff, w, h);
5528 }
5529
5530 void draw_screenunit(int32_t unit, int32_t flags)
5531 {
5532 FONT* tfont = font;
5533 switch(unit)
5534 {
5535 case rSCRMAP:
5536 {
5537 size_and_pos *mini_sqr = &minimap;
5538 size_and_pos *real_mini_sqr = &real_minimap;
5539
5540 if(zoomed_minimap)
5541 {
5542 mini_sqr = &minimap_zoomed;
5543 real_mini_sqr = &real_minimap_zoomed;
5544 }
5545
5546 auto txt_x = real_mini_sqr->x+2+8*real_mini_sqr->xscale;
5547 auto txt_y = real_mini_sqr->y+2+8*real_mini_sqr->yscale;
5548
5549 rectfill(menu1, mini_sqr->x-1, mini_sqr->y-2,mini_sqr->x+mini_sqr->w-1,mini_sqr->y+mini_sqr->h-1,jwin_pal[jcBOX]);
5550 if(zoomed_minimap)
5551 jwin_draw_frame(menu1, mini_sqr->x-1, mini_sqr->y-2,mini_sqr->w,mini_sqr->h,FR_WIN);
5552 jwin_draw_minimap_frame(menu1,real_mini_sqr->x,real_mini_sqr->y,real_mini_sqr->tw(), real_mini_sqr->th(), real_mini_sqr->xscale, FR_DEEP);
5553
5554 if(Map.getCurrMap()<Map.getMapCount())
5555 {
5556 for(int32_t i=0; i<MAPSCRS; i++)
5557 {
5558 auto& sqr = real_mini_sqr->subsquare(i);
5559
5560 if(Map.Scr(i)->valid&mVALID)
5561 {
5562 // Handled by mmap_draw.
5563 }
5564 else
5565 {
5566 if (InvalidBG == 2)
5567 {
5568 draw_checkerboard(menu1, sqr.x, sqr.y, sqr.w);
5569 }
5570 else if (InvalidBG == 1)
5571 {
5572 for(int32_t dy=0; dy<sqr.h; dy++)
5573 {
5574 for(int32_t dx=0; dx<sqr.w; dx++)
5575 {
5576 menu1->line[dy+sqr.y][dx+sqr.x]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
5577 }
5578 }
5579 }
5580 else
5581 {
5582 int32_t offs = 2*(sqr.w/9);
5583 draw_x(menu1, sqr.x+offs, sqr.y+offs, sqr.x+sqr.w-1-offs, sqr.y+sqr.h-1-offs, vc(15));
5584 }
5585 }
5586 }
5587
5588 int32_t s=Map.getCurrScr();
5589
5590 BITMAP* txtbmp = create_bitmap_ex(8,256,64);
5591 clear_bitmap(txtbmp);
5592 int txtscale = zoomed_minimap ? (is_compact ? 2 : 3) : 1;
5593 font = get_zc_font(font_lfont_l);
5594
5595 int32_t space = text_length(font, "255")+2, spc_s = text_length(font, "S")+2, spc_m = text_length(font, "M")+2;
5596 textprintf_disabled(txtbmp,font,0,0,jwin_pal[jcLIGHT],jwin_pal[jcMEDDARK],"M");
5597 static int map_shortcut_tooltip_id = ttip_register_id();
5598 ttip_install(map_shortcut_tooltip_id, "Prev map: ,\nNext map: .", txt_x, txt_y, 30, 20, txt_x, txt_y - 60);
5599
5600 textprintf_ex(txtbmp,font,spc_m,0,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%-3d",Map.getCurrMap()+1);
5601
5602 textprintf_disabled(txtbmp,font,spc_m+space,0,jwin_pal[jcLIGHT],jwin_pal[jcMEDDARK],"S");
5603 textprintf_ex(txtbmp,font,spc_m+space+spc_s,0,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"0x%02X (%d)",s, s);
5604 masked_stretch_blit(txtbmp, menu1, 0, 0, 256, 64, txt_x, txt_y, 256*txtscale, 64*txtscale);
5605 destroy_bitmap(txtbmp);
5606 }
5607 }
5608 break;
5609 case rMAP:
5610 {
5611 refresh_visible_screens();
5612 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
5613
5614 int num_combos_width = 16 * Map.getViewSize();
5615 int num_combos_height = 11 * Map.getViewSize();
5616
5617 if(CurrentLayer > 0 && !mapscreen_valid_layers[CurrentLayer-1])
5618 CurrentLayer = 0;
5619
5620 for (auto& vis_screen : visible_screens)
5621 {
5622 draw_screenunit_map_screen(vis_screen);
5623 }
5624
5625 if (showxypos_icon)
5626 {
5627 int x0 = showxypos_x + (showedges?16:0);
5628 int y0 = showxypos_y + (showedges?16:0);
5629 int x1 = x0 + showxypos_w - 1;
5630 int y1 = y0 + showxypos_h - 1;
5631 x0 *= mapscreen_single_scale;
5632 y0 *= mapscreen_single_scale;
5633 x1 *= mapscreen_single_scale;
5634 y1 *= mapscreen_single_scale;
5635 x0 += mapscreen_x;
5636 y0 += mapscreen_y;
5637 x1 += mapscreen_x;
5638 y1 += mapscreen_y;
5639
5640 if (showxypos_color == vc(15))
5641 safe_rect(menu1, x0, y0, x1, y1, showxypos_color);
5642 else
5643 rectfill(menu1, x0, y0, x1, y1, showxypos_color);
5644 }
5645
5646 if(showxypos_cursor_icon)
5647 {
5648 int x0 = showxypos_cursor_x + (showedges?16:0);
5649 int y0 = showxypos_cursor_y + (showedges?16:0);
5650 int x1 = x0 + showxypos_w - 1;
5651 int y1 = y0 + showxypos_h - 1;
5652 x0 *= mapscreen_single_scale;
5653 y0 *= mapscreen_single_scale;
5654 x1 *= mapscreen_single_scale;
5655 y1 *= mapscreen_single_scale;
5656 x0 += mapscreen_x;
5657 y0 += mapscreen_y;
5658 x1 += mapscreen_x;
5659 y1 += mapscreen_y;
5660 safe_rect(menu1, x0, y0, x1, y1, showxypos_cursor_color);
5661 }
5662
5663 // Draw dithering over the edge/preview combos.
5664 if(showedges)
5665 {
5666 int tile_size = 16 * mapscreen_single_scale;
5667 int tiles_across = (16 * Map.getViewSize()) + 2;
5668 int bottom_row_y = (Map.getViewSize()*11 + 1) * tile_size;
5669 int right_col_x = (Map.getViewSize()*16 + 1) * tile_size;
5670
5671 //top preview
5672 for(int32_t j=0; j<tile_size; j++)
5673 {
5674 for(int32_t i=0; i<tiles_across * tile_size; i++)
5675 {
5676 if(((i^j)&1)==0)
5677 {
5678 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5679 }
5680 }
5681 }
5682
5683 //bottom preview
5684 for(int32_t j = bottom_row_y; j < bottom_row_y + tile_size; j++)
5685 {
5686 for(int32_t i=0; i<tiles_across * tile_size; i++)
5687 {
5688 if(((i^j)&1)==0)
5689 {
5690 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5691 }
5692 }
5693 }
5694
5695 //left preview
5696 for(int32_t j=tile_size; j<int32_t(192*mapscreen_screenunit_scale); j++)
5697 {
5698 for(int32_t i=0; i<16*mapscreen_single_scale; i++)
5699 {
5700 if(((i^j)&1)==0)
5701 {
5702 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5703 }
5704 }
5705 }
5706
5707 //right preview
5708 for(int32_t j=tile_size; j<int32_t(192*mapscreen_screenunit_scale); j++)
5709 {
5710 for(int32_t i = right_col_x; i < right_col_x + tile_size; i++)
5711 {
5712 if(((i^j)&1)==0)
5713 {
5714 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5715 }
5716 }
5717 }
5718 }
5719
5720 if(!(Flags&cDEBUG) && pixeldb==2)
5721 {
5722 for(int32_t j=int32_t(168*mapscreen_single_scale); j<int32_t(176*mapscreen_single_scale); j++)
5723 {
5724 for(int32_t i=0; i<int32_t(256*mapscreen_single_scale); i++)
5725 {
5726
5727 if(((i^j)&1)==0)
5728 {
5729 putpixel(menu1,int32_t(mapscreen_x+(showedges?(16*mapscreen_single_scale):0)+i),
5730 int32_t(mapscreen_y+(showedges?(16*mapscreen_single_scale):0)+j),vc(blackout_color));
5731 }
5732 }
5733 }
5734 }
5735
5736 // TODO: This should move to `zmap::draw` (and delete the current code there doing a similar thing).
5737 if (Map.isDark(Map.getCurrScr()) && Map.getViewSize() == 1)
5738 {
5739 if((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM))
5740 {
5741 BITMAP* tmpDark = create_bitmap_ex(8,16*16,16*11);
5742 BITMAP* tmpDarkTrans = create_bitmap_ex(8,16*16,16*11);
5743 BITMAP* tmpbuf = create_bitmap_ex(8,
5744 mapscreen_single_scale*(256+(showedges?32:0)),
5745 mapscreen_single_scale*(176+(showedges?32:0)));
5746 BITMAP* tmpbuf2 = create_bitmap_ex(8,
5747 mapscreen_single_scale*(256+(showedges?32:0)),
5748 mapscreen_single_scale*(176+(showedges?32:0)));
5749 int32_t darkCol = zinit.darkcol;
5750 switch(darkCol) //special cases
5751 {
5752 case BLACK:
5753 darkCol = vc(0);
5754 break;
5755 case WHITE:
5756 darkCol = vc(15);
5757 break;
5758 }
5759 clear_to_color(tmpDark, darkCol);
5760 clear_to_color(tmpDarkTrans, darkCol);
5761 clear_bitmap(tmpbuf);
5762 clear_bitmap(tmpbuf2);
5763 //Handle torch combos
5764 color_map = &trans_table2;
5765 Map.draw_darkness(tmpDark, tmpDarkTrans);
5766 //
5767 mapscr* tmp = Map.CurrScr();
5768 if(tmp->flags9 & fDARK_DITHER)
5769 {
5770 ditherblit(tmpDark, tmpDark, 0, zinit.dither_type, zinit.dither_arg);
5771 ditherblit(tmpDarkTrans, tmpDarkTrans, 0, zinit.dither_type, zinit.dither_arg);
5772 }
5773
5774 if(mapscreen_single_scale == 1)
5775 {
5776 blit(tmpDark, tmpbuf, 0, 0, (showedges?16:0), (showedges?16:0), 16*16, 16*11);
5777 blit(tmpDarkTrans, tmpbuf2, 0, 0, (showedges?16:0), (showedges?16:0), 16*16, 16*11);
5778 }
5779 else
5780 {
5781 stretch_blit(tmpDark, tmpbuf, 0, 0, 16*16, 16*11,
5782 (showedges?16:0)*mapscreen_single_scale, (showedges?16:0)*mapscreen_single_scale,
5783 (16*16)*mapscreen_single_scale, (16*11)*mapscreen_single_scale);
5784 stretch_blit(tmpDarkTrans, tmpbuf2, 0, 0, 16*16, 16*11,
5785 (showedges?16:0)*mapscreen_single_scale, (showedges?16:0)*mapscreen_single_scale,
5786 (16*16)*mapscreen_single_scale, (16*11)*mapscreen_single_scale);
5787 }
5788
5789 if(tmp->flags9 & fDARK_TRANS)
5790 {
5791 draw_trans_sprite(menu1, tmpbuf, mapscreen_x, mapscreen_y);
5792 }
5793 else
5794 {
5795 masked_blit(tmpbuf,menu1,0,0,mapscreen_x,mapscreen_y,tmpbuf->w,tmpbuf->h);
5796 }
5797 draw_trans_sprite(menu1, tmpbuf2, mapscreen_x, mapscreen_y);
5798 color_map = &trans_table;
5799 //
5800 destroy_bitmap(tmpDark);
5801 destroy_bitmap(tmpDarkTrans);
5802 destroy_bitmap(tmpbuf);
5803 destroy_bitmap(tmpbuf2);
5804 }
5805 else if(!(Flags&cNODARK))
5806 {
5807 for(int32_t j=0; j<80*mapscreen_single_scale; j++)
5808 {
5809 for(int32_t i=0; i<(80*mapscreen_single_scale)-j; i++)
5810 {
5811 if(((i^j)&1)==0)
5812 {
5813 putpixel(menu1,int32_t(mapscreen_x+(showedges?(16*mapscreen_single_scale):0))+i,
5814 int32_t(mapscreen_y+(showedges?(16*mapscreen_single_scale):0)+j),vc(blackout_color));
5815 }
5816 }
5817 }
5818 }
5819 }
5820
5821 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
5822 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
5823 bool inrect = isinRect(gui_mouse_x(),gui_mouse_y(),startx,starty,(startx+(256*mapscreen_screenunit_scale)-1),(starty+(176*mapscreen_screenunit_scale)-1));
5824
5825 if(!(flags&rNOCURSOR) && ((ComboBrush && !ComboBrushPause)||draw_mode==dm_alias) && inrect)
5826 {
5827 int mgridscale=16*mapscreen_single_scale;
5828 if(allowHideMouse)
5829 {
5830 if(arrowcursor)
5831 {
5832 arrowcursor = false;
5833 MouseSprite::set(ZQM_BLANK);
5834 }
5835 }
5836 else if(!arrowcursor)
5837 {
5838 arrowcursor = true;
5839 MouseSprite::set(ZQM_NORMAL);
5840 }
5841 ComboPosition pos = get_mapscreen_mouse_combo_pos();
5842 int32_t mx = pos.x * 16 * mapscreen_single_scale;
5843 int32_t my = pos.y * 16 * mapscreen_single_scale;
5844
5845 clear_bitmap(brushscreen);
5846 int32_t tempbw=BrushWidth;
5847 int32_t tempbh=BrushHeight;
5848
5849 if(draw_mode==dm_alias)
5850 {
5851 BrushWidth = combo_aliases[combo_apos].width+1;
5852 BrushHeight = combo_aliases[combo_apos].height+1;
5853 }
5854 else if(draw_mode == dm_cpool)
5855 {
5856 BrushWidth = BrushHeight = 1;
5857 combo_pool const& pool = combo_pools[combo_pool_pos];
5858 if(pool.valid())
5859 {
5860 int32_t cid = Combo;
5861 int8_t cset = CSet;
5862 pool.get_w_wrap(cid,cset,cpoolbrush_index/16); //divide to reduce speed
5863 put_combo(brushbmp,0,0,cid,cset,Flags&(cFLAGS|cWALK),0);
5864 }
5865 else clear_bitmap(brushbmp);
5866 }
5867 else if (draw_mode == dm_auto)
5868 {
5869 BrushWidth = BrushHeight = 1;
5870 }
5871
5872 stretch_blit(brushbmp, brushscreen, 0, 0, BrushWidth*16, BrushHeight*16, 0, 0, BrushWidth*mgridscale, BrushHeight*mgridscale);
5873 int float_offx = 0;
5874 int float_offy = 0;
5875
5876 if(FloatBrush)
5877 {
5878 float_offx = -SHADOW_DEPTH*mapscreen_single_scale;
5879 float_offy = -SHADOW_DEPTH*mapscreen_single_scale;
5880
5881 //shadow
5882 for(int x = 0; x < SHADOW_DEPTH*mapscreen_single_scale; ++x)
5883 for(int y = 0; y < (BrushHeight*mgridscale) + (SHADOW_DEPTH*mapscreen_single_scale); ++y)
5884 {
5885 if((((x^y)&1)==1) && y < 12*mgridscale)
5886 putpixel(brushscreen,x+(BrushWidth*mgridscale),y,vc(0));
5887 }
5888
5889 for(int x = 0; x < BrushWidth*mgridscale; ++x)
5890 for(int y = 0; y < SHADOW_DEPTH*mapscreen_single_scale; ++y)
5891 {
5892 if((((x^y)&1)==1) && x<16*mgridscale)
5893 putpixel(brushscreen,x,y+(BrushHeight*mgridscale),vc(0));
5894 }
5895 }
5896
5897 if(draw_mode==dm_alias)
5898 {
5899 combo_alias *combo = &combo_aliases[combo_apos];
5900
5901 if(BrushWidth > 1 && (alias_origin & 1)) //right-align
5902 float_offx -= (BrushWidth - 1) * mgridscale;
5903
5904 if(BrushHeight > 1 && (alias_origin & 2)) //bottom-align
5905 float_offy -= (BrushHeight - 1) * mgridscale;
5906 }
5907
5908 int bx = mapscreen_x + mx + float_offx + (showedges?(16*mapscreen_single_scale):0);
5909 int by = mapscreen_y + my + float_offy + (showedges?(16*mapscreen_single_scale):0);
5910 masked_blit(brushscreen, menu1, 0, 0, bx, by, 16*mgridscale, 11*mgridscale);
5911 BrushWidth=tempbw;
5912 BrushHeight=tempbh;
5913 }
5914 else
5915 {
5916 if(!arrowcursor)
5917 {
5918 MouseSprite::set(ZQM_NORMAL);
5919 arrowcursor = true;
5920 }
5921 }
5922
5923 int startxint = mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
5924 int startyint = mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
5925 int endxint = startx + 256*mapscreen_screenunit_scale - 1;
5926 int endyint = starty + 176*mapscreen_screenunit_scale - 1;
5927 set_clip_rect(menu1,startxint,startyint,endxint,endyint);
5928
5929 if(ShowGrid)
5930 {
5931 int w = num_combos_width;
5932 int h = num_combos_height;
5933 double tile_size = 16.0 / Map.getViewSize() * mapscreen_screenunit_scale;
5934
5935 if(showedges)
5936 {
5937 w += 2;
5938 h += 2;
5939 }
5940
5941 for (int x = 1; x < w; x++)
5942 {
5943 vline(menu1, mapscreen_x + x*tile_size, mapscreen_y, mapscreen_y + (h*tile_size)-1, vc(GridColor));
5944 }
5945
5946 for (int y = 1; y < h; y++)
5947 {
5948 hline(menu1, mapscreen_x, mapscreen_y + y*tile_size, mapscreen_x + (w*tile_size)-1, vc(GridColor));
5949 }
5950 }
5951
5952 if(ShowScreenGrid)
5953 {
5954 int w = num_combos_width;
5955 int h = num_combos_height;
5956 double tile_size = 16.0 / Map.getViewSize() * mapscreen_screenunit_scale;
5957 int startx = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0);
5958 int starty = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0);
5959
5960 if(showedges)
5961 {
5962 w += 1;
5963 h += 1;
5964 }
5965
5966 int color = (GridColor+8)%16;
5967
5968 for (int x = 16; x < w; x+=16)
5969 {
5970 vline(menu1, startx + x*tile_size, mapscreen_y, starty + (h*tile_size)-1, vc(color));
5971 }
5972
5973 for (int y = 11; y < h; y+=11)
5974 {
5975 hline(menu1, startx, starty + y*tile_size, startx + (w*tile_size)-1, vc(color));
5976 }
5977 }
5978
5979 // Draw a rect around regions.
5980 if (ShowRegionGrid && Map.getViewSize() > 1)
5981 {
5982 for (const auto& region_description : Map.get_region_descriptions())
5983 {
5984 int sx = region_description.screen % 16;
5985 int sy = region_description.screen / 16;
5986 int sw = region_description.w;
5987 int sh = region_description.h;
5988
5989 int mw = 256 * mapscreen_single_scale;
5990 int mh = 176 * mapscreen_single_scale;
5991 int mx = sx - (Map.getViewScr() % 16);
5992 int my = sy - (Map.getViewScr() / 16);
5993 int x0 = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0) + mx * mw;
5994 int y0 = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0) + my * mh;
5995 rect(menu1, x0+2, y0+2, x0 + mw*sw - 2, y0 + mh*sh - 2, vc(1));
5996 rect(menu1, x0+1, y0+1, x0 + mw*sw - 1, y0 + mh*sh - 1, vc(15));
5997 rect(menu1, x0, y0, x0 + mw*sw, y0 + mh*sh, vc(1));
5998 }
5999 }
6000
6001 // Draw a black-yellow-black rect around the currently selected screen.
6002 if (ShowCurScreenOutline && Map.getViewSize() > 1)
6003 {
6004 int mw = 256 * mapscreen_single_scale;
6005 int mh = 176 * mapscreen_single_scale;
6006 int mx = (Map.getCurrScr() % 16) - (Map.getViewScr() % 16);
6007 int my = (Map.getCurrScr() / 16) - (Map.getViewScr() / 16);
6008 int x0 = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0) + mx * mw;
6009 int y0 = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0) + my * mh;
6010 dotted_rect(menu1, x0+2, y0+2, x0 + mw - 2, y0 + mh - 2, vc(1), vc(0));
6011 rect(menu1, x0+1, y0+1, x0 + mw - 1, y0 + mh - 1, vc(14));
6012 dotted_rect(menu1, x0, y0, x0 + mw, y0 + mh, vc(1), vc(0));
6013 }
6014
6015 clear_clip_rect(menu1);
6016
6017 // Map tabs
6018 font = get_custom_font(CFONT_GUI);
6019
6020 map_page[current_mappage].map=Map.getCurrMap();
6021 map_page[current_mappage].screen=Map.getCurrScr();
6022
6023 for(int32_t btn=0; btn<mappage_count; ++btn)
6024 {
6025 char tbuf[15];
6026 sprintf(tbuf, "%d:%02X", map_page[btn].map+1, map_page[btn].screen);
6027 draw_layer_button(menu1,map_page_bar[btn].x, map_page_bar[btn].y, map_page_bar[btn].w, map_page_bar[btn].h,tbuf,(btn==current_mappage?D_SELECTED:0));
6028 }
6029 }
6030 break;
6031 case rCOMBOS:
6032 {
6033 auto real_h = combolist_window.h;
6034 jwin_draw_frame(menu1,combolist_window.x,combolist_window.y,combolist_window.w,real_h, FR_WIN);
6035 rectfill(menu1,combolist_window.x+2,combolist_window.y+2,combolist_window.x+combolist_window.w-3,combolist_window.y+real_h-3,jwin_pal[jcBOX]);
6036
6037 //Scrollers
6038 for(int32_t c = 0; c < num_combo_cols; ++c)
6039 {
6040 auto& pos = combolistscrollers[c];
6041
6042 { //Scroll up
6043 auto& p = pos.subsquare(0);
6044 jwin_draw_frame(menu1,p.x,p.y,p.w,p.h,FR_ETCHED);
6045
6046 for(int32_t i=0; i<3; i++)
6047 {
6048 hline(menu1, p.x+5-i, p.y+4+i, p.x+5+i, jwin_pal[jcBOXFG]);
6049 }
6050 }
6051
6052 { //Scroll down
6053 auto& p = pos.subsquare(1);
6054 jwin_draw_frame(menu1,p.x,p.y,p.w,p.h,FR_ETCHED);
6055
6056 for(int32_t i=0; i<3; i++)
6057 {
6058 hline(menu1,p.x+5-i,p.y+6-i, p.x+5+i, jwin_pal[jcBOXFG]);
6059 }
6060 }
6061 }
6062
6063 if(draw_mode==dm_alias)
6064 {
6065 if(LinkedScroll)
6066 {
6067 int tmp = current_comboalist;
6068 for(int q = tmp-1; q >= 0; --q)
6069 {
6070 combo_alistpos[q] = combo_alistpos[q+1]-(comboaliaslist[q].w*comboaliaslist[q].h);
6071 if(combo_alistpos[q] < 0)
6072 {
6073 tmp = 0;
6074 combo_alistpos[0] = 0;
6075 break;
6076 }
6077 }
6078 for(int q = tmp+1; q < num_combo_cols; ++q)
6079 combo_alistpos[q] = combo_alistpos[q-1]+(comboaliaslist[q-1].w*comboaliaslist[q-1].h);
6080 for(int q = 0; q < num_combo_cols; ++q)
6081 if(combo_apos >= combo_alistpos[q] && combo_apos < combo_alistpos[q] + (comboaliaslist[q].w*comboaliaslist[q].h))
6082 {
6083 current_comboalist = q;
6084 break;
6085 }
6086 }
6087 for(int32_t c = 0; c < num_combo_cols; ++c)
6088 {
6089 auto& pos = comboaliaslist[c];
6090 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6091 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*pos.xscale)+4,(pos.h*pos.yscale)+4,FR_DEEP);
6092 }
6093
6094 auto& prev = comboalias_preview;
6095 jwin_draw_frame(menu1, prev.x-2, prev.y-2, prev.w+4, prev.h+4,FR_DEEP);
6096
6097 BITMAP *prv = create_bitmap_ex(8,64,64);
6098 clear_bitmap(prv);
6099 int32_t scalefactor = 1;
6100
6101 for(int32_t j=0; j<num_combo_cols; ++j)
6102 {
6103 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6104 if(combo_alistpos[j] + per_page >= MAXCOMBOALIASES)
6105 combo_alistpos[j] = MAXCOMBOALIASES-per_page;
6106 auto& col = comboaliaslist[j];
6107 for(int32_t i=0; i<(comboaliaslist[j].w*comboaliaslist[j].h); i++)
6108 {
6109 draw_combo_alias_thumbnail(menu1, &combo_aliases[combo_alistpos[j]+i],
6110 (i%col.w)*col.xscale+col.x, (i/col.w)*col.yscale+col.y, col.xscale/16);
6111 }
6112
6113 if((combo_aliases[combo_apos].width>7)||(combo_aliases[combo_apos].height>7))
6114 {
6115 scalefactor=4;
6116 }
6117 else if((combo_aliases[combo_apos].width>3)||(combo_aliases[combo_apos].height>3))
6118 {
6119 scalefactor=2;
6120 }
6121
6122
6123 if(j==current_comboalist)
6124 {
6125 stretch_blit(brushbmp, prv, 0,0,scalefactor*64,zc_min(scalefactor*64,176),0,0,64,scalefactor==4?44:64);
6126 blit(prv,menu1,0,0,comboalias_preview.x,comboalias_preview.y,comboalias_preview.w,comboalias_preview.h);
6127
6128 int32_t rect_pos=combo_apos-combo_alistpos[current_comboalist];
6129
6130 if((rect_pos>=0)&&(rect_pos<(combo_alistpos[current_comboalist]+(col.w*col.h))))
6131 {
6132 int selw = col.xscale;
6133 int selh = col.yscale;
6134 int x1 = (rect_pos&(col.w-1))*col.xscale+col.x;
6135 int y1 = (rect_pos/col.w)*col.yscale+col.y;
6136 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6137 }
6138 }
6139 }
6140
6141 destroy_bitmap(prv);
6142 }
6143 else if(draw_mode==dm_cpool)
6144 {
6145 if(LinkedScroll)
6146 {
6147 int tmp = current_cpoollist;
6148 for(int q = tmp-1; q >= 0; --q)
6149 {
6150 combo_pool_listpos[q] = combo_pool_listpos[q+1]-(comboaliaslist[q].w*comboaliaslist[q].h);
6151 if(combo_pool_listpos[q] < 0)
6152 {
6153 tmp = 0;
6154 combo_pool_listpos[0] = 0;
6155 break;
6156 }
6157 }
6158 for(int q = tmp+1; q < num_combo_cols; ++q)
6159 combo_pool_listpos[q] = combo_pool_listpos[q-1]+(comboaliaslist[q-1].w*comboaliaslist[q-1].h);
6160 for(int q = 0; q < num_combo_cols; ++q)
6161 if(combo_pool_pos >= combo_pool_listpos[q] && combo_pool_pos < combo_pool_listpos[q] + (comboaliaslist[q].w*comboaliaslist[q].h))
6162 {
6163 current_cpoollist = q;
6164 break;
6165 }
6166 }
6167 for(int32_t c = 0; c < num_combo_cols; ++c)
6168 {
6169 auto& pos = comboaliaslist[c];
6170 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6171 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*comboaliaslist[c].xscale)+4,(pos.h*comboaliaslist[c].yscale)+4,FR_DEEP);
6172 }
6173
6174 for (int32_t j = 0; j < num_combo_cols; ++j) //the actual panes
6175 {
6176 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6177 if(combo_pool_listpos[j] + per_page >= MAXCOMBOPOOLS)
6178 combo_pool_listpos[j] = MAXCOMBOPOOLS-per_page;
6179 for(int32_t i=0; i<(comboaliaslist[j].w*comboaliaslist[j].h); i++)
6180 {
6181 int32_t cid=-1; int8_t cs=CSet;
6182 combo_pool const& cp = combo_pools[combo_pool_listpos[j]+i];
6183
6184 auto& list = comboaliaslist[j];
6185 if(cp.get_w(cid,cs,0) && !combobuf[cid].tile)
6186 {
6187 cid = -1; //no tile to draw
6188 }
6189 auto cx = (i%list.w)*list.xscale+list.x;
6190 auto cy = (i/list.w)*list.yscale+list.y;
6191 put_combo(menu1,cx,cy,cid,cs,Flags&(cFLAGS|cWALK),0,list.xscale/16);
6192 }
6193 }
6194 int32_t rect_pos=combo_pool_pos-combo_pool_listpos[current_cpoollist];
6195
6196 if((rect_pos>=0)&&(rect_pos<(combo_pool_listpos[current_cpoollist]+(comboaliaslist[current_cpoollist].w*comboaliaslist[current_cpoollist].h))))
6197 {
6198 int selw = comboaliaslist[current_cpoollist].xscale;
6199 int selh = comboaliaslist[current_cpoollist].yscale;
6200 int x1 = (rect_pos&(comboaliaslist[current_cpoollist].w-1))*comboaliaslist[current_cpoollist].xscale+comboaliaslist[current_cpoollist].x;
6201 int y1 = (rect_pos/comboaliaslist[current_cpoollist].w)*comboaliaslist[current_cpoollist].yscale+comboaliaslist[current_cpoollist].y;
6202 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6203 }
6204
6205 //Handle Preview
6206 combo_pool const& cpool = combo_pools[combo_pool_pos];
6207
6208 int32_t cid; int8_t cs;
6209 size_t total = weighted_cpool ? cpool.getTotalWeight() : cpool.combos.size();
6210 size_t ind = 0;
6211 size_t indw = combopool_preview.w/16;
6212 size_t indh = combopool_preview.h/16;
6213 size_t rows = total ? vbound(total/indw,1,indh) : 0;
6214 if (is_compact)
6215 rows = vbound(rows, 1, 3);
6216 else
6217 rows = vbound(rows, 1, 4);
6218 size_t real_height = rows*16;
6219
6220 cpool_prev_visible = rows > 0;
6221 if(rows)
6222 {
6223 jwin_draw_frame(menu1,combopool_preview.x-2,combopool_preview.y-2,
6224 combopool_preview.w+4,real_height+4,FR_DEEP);
6225 rectfill(menu1,combopool_preview.x,combopool_preview.y,
6226 combopool_preview.x+combopool_preview.w-1,
6227 combopool_preview.y+real_height-1,vc(0));
6228 draw_text_button(menu1,combopool_prevbtn.x,combopool_prevbtn.y,
6229 combopool_prevbtn.w,combopool_prevbtn.h,
6230 weighted_cpool ? "Weighted" : "Unweighted",vc(1),vc(14),0,true);
6231 if(!is_compact)
6232 textprintf_ex(menu1,font,combopool_prevbtn.x+combopool_prevbtn.w+5,
6233 combopool_prevbtn.y,jwin_pal[jcBOXFG],-1,"Preview");
6234 for(auto y = 0; y < real_height; y += 16)
6235 {
6236 for(auto x = 0; x < combopool_preview.w; x += 16, ++ind)
6237 {
6238 auto nx = combopool_preview.x+x, ny = combopool_preview.y+y;
6239 if(ind < total)
6240 {
6241 cs = CSet;
6242 if(weighted_cpool
6243 ? cpool.get_w(cid,cs,ind)
6244 : cpool.get_ind(cid,cs,ind))
6245 {
6246 put_combo(menu1,nx,ny,cid,cs,Flags&(cFLAGS|cWALK),0);
6247 continue;
6248 }
6249 }
6250 //No combo to display
6251 xout(menu1, nx, ny, nx+15, ny+15, vc(15));
6252 }
6253 }
6254 }
6255 }
6256 else if (draw_mode == dm_auto)
6257 {
6258 if (LinkedScroll)
6259 {
6260 int tmp = current_cautolist;
6261 for (int q = tmp - 1; q >= 0; --q)
6262 {
6263 combo_auto_listpos[q] = combo_auto_listpos[q + 1] - (comboaliaslist[q].w * comboaliaslist[q].h);
6264 if (combo_auto_listpos[q] < 0)
6265 {
6266 tmp = 0;
6267 combo_auto_listpos[0] = 0;
6268 break;
6269 }
6270 }
6271 for (int q = tmp + 1; q < num_combo_cols; ++q)
6272 combo_auto_listpos[q] = combo_auto_listpos[q - 1] + (comboaliaslist[q - 1].w * comboaliaslist[q - 1].h);
6273 for (int q = 0; q < num_combo_cols; ++q)
6274 if (combo_auto_pos >= combo_auto_listpos[q] && combo_auto_pos < combo_auto_listpos[q] + (comboaliaslist[q].w * comboaliaslist[q].h))
6275 {
6276 current_cautolist = q;
6277 break;
6278 }
6279 }
6280 for (int32_t c = 0; c < num_combo_cols; ++c)
6281 {
6282 auto& pos = comboaliaslist[c];
6283 rectfill(menu1, pos.x, pos.y, pos.x + (pos.w * pos.xscale) - 1, pos.y + (pos.h * pos.yscale) - 1, 0);
6284 jwin_draw_frame(menu1, pos.x - 2, pos.y - 2, (pos.w * comboaliaslist[c].xscale) + 4, (pos.h * comboaliaslist[c].yscale) + 4, FR_DEEP);
6285 }
6286
6287 for (int32_t j = 0; j < num_combo_cols; ++j) //the actual panes
6288 {
6289 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6290 if(combo_auto_listpos[j] + per_page >= MAXAUTOCOMBOS)
6291 combo_auto_listpos[j] = MAXAUTOCOMBOS-per_page;
6292 for (int32_t i = 0; i < (comboaliaslist[j].w * comboaliaslist[j].h); i++)
6293 {
6294 int32_t cid = -1; int8_t cs = CSet;
6295 combo_auto const& ca = combo_autos[combo_auto_listpos[j] + i];
6296
6297 auto& list = comboaliaslist[j];
6298 cid = ca.getDisplay();
6299 if (cid == 0)
6300 cid = -1;
6301 auto cx = (i % list.w) * list.xscale + list.x;
6302 auto cy = (i / list.w) * list.yscale + list.y;
6303 put_combo(menu1, cx, cy, cid, cs, Flags & (cFLAGS | cWALK), 0, list.xscale / 16);
6304 put_autocombo_engravings(menu1, ca, combo_auto_listpos[j] + i == combo_auto_pos, cx, cy, list.xscale / 16);
6305 }
6306 }
6307 int32_t rect_pos = combo_auto_pos - combo_auto_listpos[current_cautolist];
6308
6309 if ((rect_pos >= 0) && (rect_pos < (combo_auto_listpos[current_cautolist] + (comboaliaslist[current_cautolist].w * comboaliaslist[current_cautolist].h))))
6310 {
6311 int selw = comboaliaslist[current_cautolist].xscale;
6312 int selh = comboaliaslist[current_cautolist].yscale;
6313 int x1 = (rect_pos & (comboaliaslist[current_cautolist].w - 1)) * comboaliaslist[current_cautolist].xscale + comboaliaslist[current_cautolist].x;
6314 int y1 = (rect_pos / comboaliaslist[current_cautolist].w) * comboaliaslist[current_cautolist].yscale + comboaliaslist[current_cautolist].y;
6315 safe_rect(menu1, x1, y1, x1 + selw - 1, y1 + selh - 1, vc(CmbCursorCol), 2);
6316
6317 combo_auto const& ca = combo_autos[combo_auto_pos];
6318 put_autocombo_engravings(menu1, ca, true, x1, y1, selw / 16);
6319 }
6320 }
6321 else
6322 {
6323 if(LinkedScroll)
6324 {
6325 int tmp = current_combolist;
6326 for(int q = tmp-1; q >= 0; --q)
6327 {
6328 First[q] = First[q+1]-(combolist[q].w*combolist[q].h);
6329 if(First[q] < 0)
6330 {
6331 tmp = 0;
6332 First[0] = 0;
6333 break;
6334 }
6335 }
6336 for(int q = tmp+1; q < num_combo_cols; ++q)
6337 First[q] = First[q-1]+(combolist[q-1].w*combolist[q-1].h);
6338 for(int q = 0; q < num_combo_cols; ++q)
6339 if(Combo >= First[q] && Combo < First[q] + (combolist[q].w*combolist[q].h))
6340 {
6341 current_combolist = q;
6342 break;
6343 }
6344 }
6345 for(int32_t c = 0; c < num_combo_cols; ++c)
6346 {
6347 auto& pos = combolist[c];
6348 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6349 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*pos.xscale)+4,(pos.h*pos.yscale)+4,FR_DEEP);
6350 }
6351
6352 int32_t drawmap, drawscr;
6353 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
6354 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
6355
6356 for(int32_t j=0; j<num_combo_cols; ++j)
6357 {
6358 auto per_page = (combolist[j].w * combolist[j].h);
6359 if(First[j] + per_page >= MAXCOMBOS)
6360 First[j] = MAXCOMBOS-per_page;
6361 for(int32_t i=0; i<(combolist[j].w*combolist[j].h); i++)
6362 {
6363 put_combo(menu1,(i%combolist[j].w)*combolist[j].xscale+combolist[j].x,
6364 (i/combolist[j].w)*combolist[j].yscale+combolist[j].y,
6365 i+First[j],CSet,Flags&(cFLAGS|cWALK),0,combolist[j].xscale/16);
6366 }
6367 }
6368
6369 int32_t rect_pos=Combo-First[current_combolist];
6370
6371 if((rect_pos>=0)&&(rect_pos<(combo_pool_listpos[current_combolist]+(combolist[current_combolist].w*combolist[current_combolist].h))))
6372 {
6373 int selw = (AutoBrush?BrushWidth:1)*combolist[current_combolist].xscale;
6374 int selh = (AutoBrush?BrushHeight:1)*combolist[current_combolist].yscale;
6375 int x1 = (rect_pos&(combolist[current_combolist].w-1))*combolist[current_combolist].xscale+combolist[current_combolist].x;
6376 int y1 = (rect_pos/combolist[current_combolist].w)*combolist[current_combolist].yscale+combolist[current_combolist].y;
6377 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6378 }
6379 }
6380 }
6381 break;
6382 case rCOMBO:
6383 {
6384 int32_t drawmap, drawscr;
6385 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
6386 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
6387
6388 // Combo preview
6389 int32_t cid = Combo; int8_t cs = CSet;
6390 if(draw_mode == dm_alias)
6391 {
6392 cid = combo_aliases[combo_apos].combos[0];
6393 cs = wrap(combo_aliases[combo_apos].csets[0]+alias_cset_mod, 0, 13);
6394 }
6395 else if(draw_mode == dm_cpool)
6396 {
6397 combo_pool const& cpool = combo_pools[combo_pool_pos];
6398 cid = 0;
6399 cpool.get_w(cid,cs,0);
6400 }
6401 else if (draw_mode == dm_auto)
6402 {
6403 combo_auto const& cauto = combo_autos[combo_auto_pos];
6404 cid = cauto.getDisplay();
6405 }
6406 static BITMAP *combo_preview_bmp=create_bitmap_ex(8,32,32);
6407 static BITMAP *cycle_preview_bmp=create_bitmap_ex(8,32,32);
6408 // Combo
6409 put_combo(combo_preview_bmp,0,0,cid,cs,Flags&(cFLAGS|cWALK),0);
6410 jwin_draw_frame(menu1,combo_preview.x-2,combo_preview.y-2,combo_preview.w+4,combo_preview.h+4, FR_DEEP);
6411 stretch_blit(combo_preview_bmp, menu1, 0, 0, 16, 16, combo_preview.x, combo_preview.y, combo_preview.w, combo_preview.h);
6412
6413 comboprev_buf[0] = 0;
6414 comboprev_buf2[0] = 0;
6415 if(draw_mode == dm_cpool)
6416 {
6417 sprintf(comboprev_buf,"Pool: %d\nCSet: %d",combo_pool_pos,CSet);
6418 int x = combo_preview_text1.x+(combo_preview_text1.w*combo_preview_text1.xscale);
6419 textbox_out(menu1,txfont,x,combo_preview_text1.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],comboprev_buf,2,&combo_preview_text1);
6420 }
6421 else if (draw_mode == dm_auto)
6422 {
6423 GUI::ListData ac_types = GUI::ZCListData::autocombotypes();
6424 std::string type_name = ac_types.findText(combo_autos[combo_auto_pos].getType());
6425 if (is_compact)
6426 sprintf(comboprev_buf, "AC: %d CS: %d\n%s", combo_auto_pos, CSet, type_name.c_str());
6427 else
6428 sprintf(comboprev_buf, "Auto: %d CSet: %d\n%s\nEntries: %d", combo_auto_pos, CSet, type_name.c_str(), int32_t(combo_autos[combo_auto_pos].combos.size()));
6429 int x = combo_preview_text1.x + (combo_preview_text1.w * combo_preview_text1.xscale);
6430 textbox_out(menu1, txfont, x, combo_preview_text1.y, jwin_pal[jcBOXFG], jwin_pal[jcBOX], comboprev_buf, 2, &combo_preview_text1);
6431 }
6432 else if(draw_mode != dm_alias)
6433 {
6434 int x = combo_preview_text1.x+(combo_preview_text1.w*combo_preview_text1.xscale);
6435
6436 char shortbuf[512];
6437 char buf[256];
6438 strcpy(buf,combo_class_buf[combobuf[Combo].type].name);
6439 sprintf(comboprev_buf,"Combo: %d\nCSet: %d\n%s",Combo,CSet,buf);
6440 int ind = strlen(buf)-1;
6441 int x2 = x;
6442 if(x2 - text_length(txfont, buf) <= combolist_window.x)
6443 {
6444 auto dotlen = text_length(txfont, "..");
6445 x2 -= dotlen;
6446 while(x2 - text_length(txfont, buf) <= combolist_window.x)
6447 {
6448 if(ind < 0) break;
6449 buf[ind--] = '\0';
6450 }
6451 while(ind >= 0 && buf[ind] == ' ')
6452 buf[ind--] = 0; //trim spaces
6453 strcat(buf, "..");
6454 }
6455
6456 if(is_compact)
6457 {
6458 char b2[256];
6459 sprintf(b2, "Combo %d CS %d", Combo, CSet);
6460 if(x-text_length(txfont, b2) <= combolist_window.x)
6461 sprintf(b2, "Cmb %d CS %d", Combo, CSet);
6462 sprintf(shortbuf,"%s\n%s",b2,buf);
6463 }
6464 else sprintf(shortbuf,"Combo: %d\nCSet: %d\n%s",Combo,CSet,buf);
6465 textbox_out(menu1,txfont,x,combo_preview_text1.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],shortbuf,2,&combo_preview_text1);
6466 }
6467
6468 // Cycle
6469 if(!is_compact)
6470 {
6471 int32_t NextCombo = combobuf[Combo].nextcombo;
6472 int32_t NextCSet = combobuf[Combo].nextcset;
6473 if(combobuf[Combo].animflags & AF_CYCLEUNDERCOMBO)
6474 {
6475 mapscr* scr = Map.CurrScr();
6476 NextCombo = scr->undercombo;
6477 NextCSet = scr->undercset;
6478 }
6479 if(combobuf[Combo].animflags & AF_CYCLENOCSET)
6480 NextCSet = CSet;
6481 bool normal_dm = draw_mode != dm_alias && draw_mode != dm_cpool && draw_mode != dm_auto;
6482 jwin_draw_frame(menu1,combo_preview2.x-2,combo_preview2.y-2,combo_preview2.w+4,combo_preview2.h+4, FR_DEEP);
6483 if(NextCombo>0 && normal_dm)
6484 {
6485 put_combo(cycle_preview_bmp,0,0,NextCombo,NextCSet,Flags&(cFLAGS|cWALK),0);
6486
6487 if(Flags&cWALK) put_walkflags(cycle_preview_bmp,0,0,NextCombo,0);
6488
6489 if(Flags&cFLAGS) put_flags(cycle_preview_bmp,0,0,NextCombo,0,cFLAGS,0);
6490
6491 stretch_blit(cycle_preview_bmp, menu1, 0, 0, 16, 16, combo_preview2.x, combo_preview2.y, combo_preview2.w, combo_preview2.h);
6492 }
6493 else
6494 {
6495 if (InvalidBG == 2)
6496 {
6497 draw_checkerboard(menu1, combo_preview2.x, combo_preview2.y, 32);
6498 }
6499 else if(InvalidBG == 1)
6500 {
6501 for(int32_t dy=0; dy<combo_preview2.w; dy++)
6502 {
6503 for(int32_t dx=0; dx<combo_preview2.w; dx++)
6504 {
6505 menu1->line[dy+combo_preview2.y][dx+combo_preview2.x]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
6506 }
6507 }
6508 }
6509 else
6510 {
6511 rectfill(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(0));
6512 safe_rect(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(15));
6513 line(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(15));
6514 line(menu1, combo_preview2.x,combo_preview2.y+combo_preview2.h, combo_preview2.x+32,combo_preview2.y,vc(15));
6515 }
6516 }
6517
6518 if(normal_dm)
6519 {
6520 char shortbuf[512];
6521 char buf[256];
6522 strcpy(buf,combo_class_buf[combobuf[NextCombo].type].name);
6523 sprintf(comboprev_buf2, "Cycle: %d\nCSet: %d\n%s", NextCombo, NextCSet, buf);
6524 int ind = strlen(buf)-1;
6525 int x2 = combo_preview_text2.x;
6526 if(x2 + text_length(txfont, buf) > zq_screen_w-2)
6527 {
6528 auto dotlen = text_length(txfont, "..");
6529 x2 += dotlen;
6530 while(x2 + text_length(txfont, buf) > zq_screen_w-2)
6531 {
6532 if(ind < 0) break;
6533 buf[ind--] = '\0';
6534 }
6535 while(ind >= 0 && buf[ind] == ' ')
6536 buf[ind--] = 0; //trim spaces
6537 strcat(buf, "..");
6538 }
6539
6540 sprintf(shortbuf, "Cycle: %d\nCSet: %d\n%s", NextCombo, NextCSet, buf);
6541 textbox_out(menu1,txfont,combo_preview_text2.x,combo_preview_text2.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],shortbuf,0,&combo_preview_text2);
6542 }
6543 }
6544
6545 font = get_zc_font(font_lfont_l);
6546 bool merged = is_compact ? compact_merged_combopane : large_merged_combopane;
6547 draw_text_button(menu1,combo_merge_btn.x,combo_merge_btn.y,combo_merge_btn.w,combo_merge_btn.h,merged ? "<|>" : ">|<",vc(1),vc(14),0,true);
6548 }
6549 break;
6550 case rFAVORITES:
6551 {
6552 font = get_zc_font(font_lfont_l);
6553
6554 jwin_draw_frame(menu1,favorites_window.x,favorites_window.y,favorites_window.w,favorites_window.h, FR_WIN);
6555 rectfill(menu1,favorites_window.x+2,favorites_window.y+2,favorites_window.x+favorites_window.w-3,favorites_window.y+favorites_window.h-3,jwin_pal[jcBOX]);
6556 jwin_draw_frame(menu1,favorites_list.x-2,favorites_list.y-2,(favorites_list.w*favorites_list.xscale)+4,(favorites_list.h*favorites_list.yscale)+4, FR_DEEP);
6557 rectfill(menu1,favorites_list.x,favorites_list.y,favorites_list.x+(favorites_list.w*favorites_list.xscale)-1,favorites_list.y+(favorites_list.h*favorites_list.yscale)-1,jwin_pal[jcBOXFG]);
6558
6559 textprintf_ex(menu1,get_zc_font(font_lfont_l),favorites_list.x-2,favorites_list.y-15,jwin_pal[jcBOXFG],-1,is_compact ? "Favorites" : "Favorite Combos");
6560 BITMAP* subb = create_bitmap_ex(8,16,16);
6561
6562 for(int32_t col=0; col<favorites_list.w; ++col)
6563 {
6564 for(int32_t row=0; row<favorites_list.h; ++row)
6565 {
6566 auto i = (row*FAVORITECOMBO_PER_ROW)+col+FAVORITECOMBO_PER_PAGE*FavoriteComboPage;
6567 auto& sqr = favorites_list.subsquare(col,row);
6568 if(i >= MAXFAVORITECOMBOS || favorite_combos[i]==-1)
6569 {
6570 if (InvalidBG == 2)
6571 {
6572 draw_checkerboard(menu1, sqr.x, sqr.y, sqr.w);
6573 }
6574 else if(InvalidBG == 1)
6575 {
6576 for(int32_t dy=0; dy<sqr.h; dy++)
6577 {
6578 for(int32_t dx=0; dx<sqr.w; dx++)
6579 {
6580 menu1->line[sqr.y+dy][sqr.x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
6581 }
6582 }
6583 }
6584 else
6585 {
6586 xout(menu1, sqr.x, sqr.y, sqr.x+sqr.w-1, sqr.y+sqr.h-1, vc(15), vc(0));
6587 }
6588 }
6589 else
6590 {
6591 clear_bitmap(subb);
6592 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
6593
6594 switch(favorite_combo_modes[i])
6595 {
6596 case dm_alias:
6597 draw_combo_alias_thumbnail(subb, &combo_aliases[favorite_combos[i]], 0, 0, 1);
6598 if (ShowFavoriteComboModes)
6599 put_engraving(subb, 0, 0, 0x3E, 1);
6600 break;
6601 case dm_cpool:
6602 {
6603 int32_t cid = -1; int8_t cs = CSet;
6604 combo_pool const& cp = combo_pools[favorite_combos[i]];
6605
6606 if (cp.get_w(cid, cs, 0) && !combobuf[cid].tile)
6607 cid = -1; //no tile to draw
6608 put_combo(subb, 0, 0, cid, cs, 0, 0);
6609 if (ShowFavoriteComboModes)
6610 put_engraving(subb, 0, 0, 0x3D, 1);
6611 break;
6612 }
6613 case dm_auto:
6614 {
6615 int32_t cid = -1; int8_t cs = CSet;
6616 combo_auto const& ca = combo_autos[favorite_combos[i]];
6617
6618 cid = ca.getDisplay();
6619 if (cid == 0)
6620 cid = -1;
6621 put_combo(subb, 0, 0, cid, cs, 0, 0);
6622 if (ShowFavoriteComboModes)
6623 put_engraving(subb, 0, 0, 0x3C, 1);
6624 break;
6625 }
6626 default:
6627 if (repos)
6628 {
6629 combotile_override_x = sqr.x + (sqr.w - 16) / 2;
6630 combotile_override_y = sqr.y + (sqr.h - 16) / 2;
6631 }
6632 put_combo(subb, 0, 0, favorite_combos[i], CSet, Flags & (cFLAGS | cWALK), 0);
6633 if (repos) combotile_override_x = combotile_override_y = -1;
6634 }
6635 stretch_blit(subb, menu1, 0, 0, 16, 16, sqr.x, sqr.y, sqr.w, sqr.h);
6636 }
6637 }
6638 }
6639
6640 destroy_bitmap(subb);
6641
6642 bool zoomed = is_compact ? compact_zoomed_fav : large_zoomed_fav;
6643 if(!is_compact)
6644 textprintf_right_ex(menu1, get_zc_font(font_lfont_l), favorites_pgleft.x - 2, favorites_pgleft.y, jwin_pal[jcBOXFG], -1, "%d/9", FavoriteComboPage + 1);
6645
6646 draw_text_button(menu1, favorites_pgleft.x, favorites_pgleft.y, favorites_pgleft.w, favorites_pgleft.h, is_compact ? "<" : "<-", vc(1), vc(14), 0, true);
6647 draw_text_button(menu1, favorites_pgright.x, favorites_pgright.y, favorites_pgright.w, favorites_pgright.h, is_compact ? ">" : "->", vc(1), vc(14), 0, true);
6648 draw_text_button(menu1,favorites_zoombtn.x,favorites_zoombtn.y,favorites_zoombtn.w,favorites_zoombtn.h,zoomed ? "-" : "+",vc(1),vc(14),0,true);
6649 draw_text_button(menu1,favorites_x.x,favorites_x.y,favorites_x.w,favorites_x.h,"X",vc(1),vc(14),0,true);
6650 draw_text_button(menu1,favorites_infobtn.x,favorites_infobtn.y,favorites_infobtn.w,favorites_infobtn.h,"?",vc(1),vc(14),0,true);
6651 }
6652 break;
6653 case rCOMMANDS:
6654 {
6655 jwin_draw_frame(menu1,commands_window.x,commands_window.y,commands_window.w,commands_window.h, FR_WIN);
6656 rectfill(menu1,commands_window.x+2,commands_window.y+2,commands_window.x+commands_window.w-3,commands_window.y+commands_window.h-3,jwin_pal[jcBOX]);
6657 jwin_draw_frame(menu1,commands_list.x-2,commands_list.y-2,(commands_list.w*commands_list.xscale)+4,(commands_list.h*commands_list.yscale)+4, FR_DEEP);
6658 rectfill(menu1,commands_list.x,commands_list.y,commands_list.x+(commands_list.w*commands_list.xscale)-1,commands_list.y+(commands_list.h*commands_list.yscale)-1,jwin_pal[jcBOXFG]);
6659 font=get_custom_font(CFONT_FAVCMD);
6660
6661 for(int32_t cmd=0; cmd<(commands_list.w*commands_list.h); ++cmd)
6662 {
6663 uint hkey = favorite_commands[cmd];
6664 draw_layer_button(menu1,
6665 (cmd%commands_list.w)*commands_list.xscale+commands_list.x,
6666 (cmd/commands_list.w)*commands_list.yscale+commands_list.y,
6667 commands_list.xscale,
6668 commands_list.yscale,
6669 get_hotkey_name(hkey),
6670 (selected_hotkey(hkey)?D_SELECTED:0) | (disabled_hotkey(hkey)?D_DISABLED:0));
6671 }
6672
6673 font = get_zc_font(font_lfont_l);
6674 if(commands_txt.x > 0)
6675 {
6676 gui_textout_ln(menu1, get_zc_font(font_lfont_l), (ucc*)"Favorite Commands", commands_txt.x, commands_txt.y, jwin_pal[jcBOXFG], -1, 0);
6677 }
6678
6679 bool zoomed = is_compact ? compact_zoomed_cmd : large_zoomed_cmd;
6680 draw_text_button(menu1,commands_zoombtn.x,commands_zoombtn.y,commands_zoombtn.w,commands_zoombtn.h,zoomed ? "-" : "+",vc(1),vc(14),0,true);
6681 draw_text_button(menu1,commands_x.x,commands_x.y,commands_x.w,commands_x.h,"X",vc(1),vc(14),0,true);
6682 draw_text_button(menu1,commands_infobtn.x,commands_infobtn.y,commands_infobtn.w,commands_infobtn.h,"?",vc(1),vc(14),0,true);
6683 }
6684 break;
6685 }
6686 font = tfont;
6687 }
6688
6689 bool pause_refresh = true;
6690 bool is_refreshing = false;
6691 11 void refresh(int32_t flags, bool update)
6692 {
6693
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(pause_refresh) return;
6694 static bool refreshing = false;
6695
6696 int num_screens_to_draw = Map.getViewSize();
6697
6698 bool earlyret = refreshing;
6699 is_refreshing = refreshing = true;
6700 //^ These prevent recursive calls from updating the screen early
6701
6702 bool zoom_delay = (zoomed_minimap && flags != rSCRMAP);
6703 if(zoom_delay)
6704 flags &= ~rSCRMAP;
6705
6706 if(flags&rCLEAR)
6707 {
6708 //magic pink = 0xED
6709 //system black = vc(0)
6710 //Clear a4 menu
6711 clear_to_color(menu1,jwin_pal[jcBOX]);
6712
6713 //Clears should refresh everything!
6714 flags |= rALL;
6715 }
6716
6717 if(flags&rSCRMAP)
6718 draw_screenunit(rSCRMAP,flags);
6719
6720 if(flags&rMAP)
6721 draw_screenunit(rMAP,flags);
6722
6723 if((flags&rCOMBOS) || (draw_mode == dm_cpool && (flags&rFAVORITES)))
6724 draw_screenunit(rCOMBOS,flags);
6725
6726 if(flags&(rCOMBO|rCOMBOS))
6727 draw_screenunit(rCOMBO,flags);
6728
6729 if(flags&rMENU)
6730 drawpanel();
6731
6732 if(flags&rFAVORITES)
6733 draw_screenunit(rFAVORITES,flags);
6734
6735 if(flags&rCOMMANDS)
6736 draw_screenunit(rCOMMANDS,flags);
6737
6738 FONT* tfont = font;
6739 font = get_custom_font(CFONT_GUI);
6740 jwin_draw_frame(menu1,layer_panel.x,layer_panel.y,layer_panel.w,layer_panel.h,FR_DEEP);
6741 rectfill(menu1,layer_panel.x,layer_panel.y,layer_panel.x+layer_panel.w-1,layer_panel.y+layer_panel.h-1,jwin_pal[jcBOX]);
6742
6743 for(int32_t i=0; i<=6; ++i)
6744 {
6745 char tbuf[15];
6746
6747 if (i>0 && mapscreen_valid_layers[i - 1] && num_screens_to_draw == 1)
6748 {
6749 if(is_compact)
6750 sprintf(tbuf, "%s%d %d:%02X", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
6751 else sprintf(tbuf, "%s%d (%d:%02X)", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
6752 }
6753 else
6754 {
6755 sprintf(tbuf, "%s%d", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i);
6756 }
6757
6758 int32_t spacing_offs = is_compact ? 2 : 10;
6759 int32_t rx = (i * (layerpanel_buttonwidth+spacing_offs+layerpanel_checkbox_wid)) + layer_panel.x+(is_compact?2:6);
6760 int32_t ry = layer_panel.y;
6761 auto cbyofs = (layerpanel_buttonheight-layerpanel_checkbox_hei)/2;
6762 draw_layer_button(menu1, rx, ry, layerpanel_buttonwidth, layerpanel_buttonheight, tbuf, CurrentLayer==i? D_SELECTED : ( i > 0 && !mapscreen_valid_layers[i-1]) ? D_DISABLED : 0);
6763 draw_checkbox(menu1,rx+layerpanel_buttonwidth+1,ry+cbyofs,layerpanel_checkbox_wid,layerpanel_checkbox_hei,LayerMaskInt[i]!=0);
6764 }
6765
6766 font=tfont;
6767
6768 // } //if(true)
6769 if(zq_showpal)
6770 {
6771 for(int32_t i=0; i<256; i++)
6772 {
6773 rectfill(menu1,((i&15)<<2)+256,((i>>4)<<2)+176,((i&15)<<2)+259,((i>>4)<<2)+179,i);
6774 }
6775 }
6776 { //Show top-left info
6777 size_t maxwid = (mapscreen_screenunit_scale*mapscreenbmp->w)-1;
6778 size_t maxhei = (mapscreen_screenunit_scale*mapscreenbmp->w);
6779 set_clip_rect(menu1,mapscreen_x,mapscreen_y,mapscreen_x+maxwid-1,mapscreen_y+maxhei-1);
6780 FONT* showfont = get_custom_font(CFONT_INFO);
6781 int showfont_h = text_height(showfont);
6782 int32_t ypos = mapscreen_y;
6783 if(prv_mode)
6784 {
6785 textout_shadowed_ex(menu1,showfont,"Preview Mode",0,ypos,vc(15),vc(0),infobg?vc(0):-1);
6786 ypos += showfont_h+1;
6787 if(prv_twon)
6788 {
6789 textprintf_shadowed_ex(menu1,showfont,0,ypos,vc(15),vc(0),infobg?vc(0):-1,"T Warp=%d tics", Map.get_prvtime());
6790 ypos += showfont_h+1;
6791 }
6792 }
6793 if(ShowFPS)
6794 {
6795 textprintf_shadowed_ex(menu1,showfont,0,ypos,vc(15),vc(0),infobg?vc(0):-1,"FPS: %3d",lastfps);
6796 ypos += showfont_h+1;
6797 }
6798
6799 if(ShowFFScripts && !prv_mode)
6800 {
6801 word num_ffcs = Map.CurrScr()->numFFC();
6802 for(word i=0; i< num_ffcs; i++)
6803 {
6804 if(ypos+showfont_h-1 > map_page_bar[0].y)
6805 break;
6806 if(Map.CurrScr()->ffcs[i].script && Map.CurrScr()->ffcs[i].data)
6807 {
6808 textout_shadowed_ex(menu1, showfont, ffcmap[Map.CurrScr()->ffcs[i].script-1].scriptname.substr(0,300).c_str(),0,ypos,vc(showxypos_ffc==i ? 14 : 15),vc(0),infobg?vc(0):-1);
6809 ypos+=showfont_h+1;
6810 }
6811 }
6812 }
6813 clear_clip_rect(menu1);
6814 if(prv_mode)
6815 do_previewtext();
6816 }
6817 // Show Errors & Details
6818 //This includes the presence of: Screen State Carryover, Timed Warp, Maze Path, the 'Sideview Gravity', 'Invisible Hero',
6819 //'Save Screen', 'Continue Here' and 'Treat As..' Screen Flags,
6820 // the String, every Room Type and Catch All, and all four Tile and Side Warps.
6821 if(!prv_mode && ShowInfo)
6822 {
6823 int32_t i=0;
6824 char buf[2048];
6825
6826 // Start with general information
6827 if(Map.CurrScr()->flags3&fINVISHERO)
6828 {
6829 sprintf(buf,"Invisible Hero");
6830 show_screen_error(buf,i++,vc(15));
6831 }
6832
6833 if(Map.getLayerTargetMap() > 0)
6834 {
6835 Map.setlayertarget(); //Now the text does not carry over when changing maps, but shifting back, it does not **re-appear** until you change screens.
6836 //It was also required to set some updates in onDecMap and onIncMap. #
6837 //This fixes Screen Info not displaying properly when changing maps. -Z
6838 //Needed to refresh the screen info. -Z ( 26th March, 2019 )
6839 int32_t m = Map.getLayerTargetMultiple();
6840 sprintf(buf,"Used as a layer by screen %d:%02X",Map.getLayerTargetMap(),Map.getLayerTargetScr());
6841 char buf2[24];
6842
6843 if(m>0)
6844 {
6845 sprintf(buf2," and %d other%s",m,m>1?"s":"");
6846 strcat(buf,buf2);
6847 }
6848
6849 show_screen_error(buf,i++,vc(15));
6850 }
6851
6852 if(Map.CurrScr()->nextmap)
6853 {
6854 sprintf(buf,"Screen State carries over to %d:%02X",Map.CurrScr()->nextmap,Map.CurrScr()->nextscr);
6855 show_screen_error(buf,i++,vc(15));
6856 }
6857
6858 if(Map.CurrScr()->timedwarptics)
6859 {
6860 sprintf(buf,"%s%sTimed Warp: %s",(Map.CurrScr()->flags4&fTIMEDDIRECT)?"Direct ":"",(Map.CurrScr()->flags5&fRANDOMTIMEDWARP)?"Random ":"",ticksstr(Map.CurrScr()->timedwarptics));
6861 show_screen_error(buf,i++,vc(15));
6862 }
6863
6864 if(Map.CurrScr()->flags&fMAZE)
6865 {
6866 sprintf(buf,"Maze Path: %s (Exit %s)",pathstr(Map.CurrScr()->path),mazedirstr[Map.CurrScr()->exitdir]);
6867 show_screen_error(buf,i++,vc(15));
6868 }
6869
6870 bool continuescreen = false, savecombo = false;
6871
6872 if(Map.CurrScr()->flags4&fAUTOSAVE)
6873 {
6874 sprintf(buf,"Automatic Save%s Screen", (Map.CurrScr()->flags6&fCONTINUEHERE) ? "-Continue":"");
6875 show_screen_error(buf,i++,vc(15));
6876 continuescreen = ((Map.CurrScr()->flags6&fCONTINUEHERE)!=0);
6877 savecombo = true;
6878 }
6879 else if(Map.CurrScr()->flags6&fCONTINUEHERE)
6880 {
6881 sprintf(buf,"Continue Screen");
6882 show_screen_error(buf,i++,vc(15));
6883 continuescreen = true;
6884 }
6885
6886 if(isSideViewGravity())
6887 {
6888 sprintf(buf,"Sideview Gravity");
6889 show_screen_error(buf,i++,vc(15));
6890 }
6891
6892 if(Map.CurrScr()->flags6 & (fCAVEROOM|fDUNGEONROOM))
6893 {
6894 sprintf(buf,"Treat As %s%s Screen", (Map.CurrScr()->flags6&fCAVEROOM) ? "Interior":"NES Dungeon",
6895 (Map.CurrScr()->flags6 & (fCAVEROOM|fDUNGEONROOM)) == (fCAVEROOM|fDUNGEONROOM) ? " or NES Dungeon":"");
6896 show_screen_error(buf,i++,vc(15));
6897 }
6898
6899 if(Map.CurrScr()->oceansfx != 0)
6900 {
6901 sprintf(buf,"Ambient Sound: %s",sfx_string[Map.CurrScr()->oceansfx]);
6902 show_screen_error(buf,i++,vc(15));
6903 }
6904
6905 if(Map.CurrScr()->bosssfx != 0)
6906 {
6907 sprintf(buf,"Boss Roar Sound: %s",sfx_string[Map.CurrScr()->bosssfx]);
6908 show_screen_error(buf,i++,vc(15));
6909 }
6910
6911 if(Map.CurrScr()->str)
6912 {
6913 strncpy(buf,MsgString(Map.CurrScr()->str, true, false),72);
6914 buf[72] = '\0';
6915 char shortbuf[72];
6916 strip_extra_spaces(buf);
6917 shorten_string(shortbuf, buf, get_zc_font(font_lfont_l), 72, 280);
6918 sprintf(buf,"String %s",shortbuf);
6919 show_screen_error(buf,i++,vc(15));
6920 }
6921
6922 if((Map.CurrScr()->flags&fWHISTLE) || (Map.CurrScr()->flags7&fWHISTLEWATER))
6923 {
6924 sprintf(buf,"Whistle ->%s%s%s",(Map.CurrScr()->flags&fWHISTLE)?" Stairs":"",
6925 (Map.CurrScr()->flags&fWHISTLE && Map.CurrScr()->flags7&fWHISTLEWATER)?", ":"",
6926 (Map.CurrScr()->flags7&fWHISTLEWATER)?"Dry Lake":"");
6927 show_screen_error(buf,i++,vc(15));
6928 }
6929
6930 switch(Map.CurrScr()->room)
6931 {
6932 case rSP_ITEM:
6933 sprintf(buf,"Special Item is %s",item_string[Map.CurrScr()->catchall]);
6934 show_screen_error(buf,i++, vc(15));
6935 break;
6936
6937 case rINFO:
6938 {
6939 int32_t shop = Map.CurrScr()->catchall;
6940 sprintf(buf,"Pay For Info: -%d, -%d, -%d",
6941 QMisc.info[shop].price[0],QMisc.info[shop].price[1],QMisc.info[shop].price[2]);
6942 show_screen_error(buf,i++, vc(15));
6943 }
6944 break;
6945
6946 case rMONEY:
6947 sprintf(buf,"Secret Money: %d Rupees",Map.CurrScr()->catchall);
6948 show_screen_error(buf,i++, vc(15));
6949 break;
6950
6951 case rGAMBLE:
6952 show_screen_error("Gamble Room",i++, vc(15));
6953 break;
6954
6955 case rREPAIR:
6956 sprintf(buf,"Door Repair: -%d Rupees",Map.CurrScr()->catchall);
6957 show_screen_error(buf,i++, vc(15));
6958 break;
6959
6960 case rRP_HC:
6961 sprintf(buf,"Take %s or %s", item_string[iRPotion], item_string[iHeartC]);
6962 show_screen_error(buf,i++, vc(15));
6963 break;
6964
6965 case rGRUMBLE:
6966 show_screen_error("Feed the Goriya",i++, vc(15));
6967 break;
6968
6969 case rTRIFORCE:
6970 show_screen_error("Triforce Check",i++, vc(15));
6971 break;
6972
6973 case rP_SHOP:
6974 case rSHOP:
6975 {
6976 int32_t shop = Map.CurrScr()->catchall;
6977 sprintf(buf,"%sShop: ",
6978 Map.CurrScr()->room==rP_SHOP ? "Potion ":"");
6979
6980 for(int32_t j=0; j<3; j++) if(QMisc.shop[shop].item[j]>0) // Print the 3 items and prices
6981 {
6982 strcat(buf,item_string[QMisc.shop[shop].item[j]]);
6983 strcat(buf,":");
6984 char pricebuf[8];
6985 sprintf(pricebuf,"%d",QMisc.shop[shop].price[j]);
6986 strcat(buf,pricebuf);
6987
6988 if(j<2 && QMisc.shop[shop].item[j+1]>0) strcat(buf,", ");
6989 }
6990
6991 show_screen_error(buf,i++, vc(15));
6992 }
6993 break;
6994
6995 case rBOTTLESHOP:
6996 {
6997 int32_t shop = Map.CurrScr()->catchall;
6998 sprintf(buf,"Bottle Shop: ");
6999
7000 for(int32_t j=0; j<3; j++) if(QMisc.bottle_shop_types[shop].fill[j]>0) // Print the 3 fills and prices
7001 {
7002 strcat(buf,QMisc.bottle_types[QMisc.bottle_shop_types[shop].fill[j]-1].name);
7003 strcat(buf,":");
7004 char pricebuf[8];
7005 sprintf(pricebuf,"%d",QMisc.bottle_shop_types[shop].price[j]);
7006 strcat(buf,pricebuf);
7007
7008 if(j<2 && QMisc.bottle_shop_types[shop].fill[j+1]>0) strcat(buf,", ");
7009 }
7010
7011 show_screen_error(buf,i++, vc(15));
7012 }
7013 break;
7014
7015 case rTAKEONE:
7016 {
7017 int32_t shop = Map.CurrScr()->catchall;
7018 sprintf(buf,"Take Only One: %s%s%s%s%s",
7019 QMisc.shop[shop].item[0]<1?"":item_string[QMisc.shop[shop].item[0]],QMisc.shop[shop].item[0]>0?", ":"",
7020 QMisc.shop[shop].item[1]<1?"":item_string[QMisc.shop[shop].item[1]],(QMisc.shop[shop].item[1]>0&&QMisc.shop[shop].item[2]>0)?", ":"",
7021 QMisc.shop[shop].item[2]<1?"":item_string[QMisc.shop[shop].item[2]]);
7022 show_screen_error(buf,i++, vc(15));
7023 }
7024 break;
7025
7026 case rBOMBS:
7027 sprintf(buf,"More Bombs: -%d Rupees",Map.CurrScr()->catchall);
7028 show_screen_error(buf,i++, vc(15));
7029 break;
7030
7031 case rARROWS:
7032 sprintf(buf,"More Arrows: -%d Rupees",Map.CurrScr()->catchall);
7033 show_screen_error(buf,i++, vc(15));
7034 break;
7035
7036 case rSWINDLE:
7037 sprintf(buf,"Leave Life or %d Rupees",Map.CurrScr()->catchall);
7038 show_screen_error(buf,i++, vc(15));
7039 break;
7040
7041 case r10RUPIES:
7042 show_screen_error("10 Rupees",i++, vc(15));
7043 break;
7044
7045 case rGANON:
7046 show_screen_error("Ganon Room",i++, vc(15));
7047 break;
7048
7049 case rZELDA:
7050 show_screen_error("Zelda Room",i++, vc(15));
7051 break;
7052
7053 case rMUPGRADE:
7054 show_screen_error("1/2 Magic Upgrade",i++, vc(15));
7055 break;
7056
7057 case rLEARNSLASH:
7058 show_screen_error("Learn Slash",i++, vc(15));
7059 break;
7060
7061 case rWARP:
7062 sprintf(buf,"3-Stair Warp: Warp Ring %d",Map.CurrScr()->catchall);
7063 show_screen_error(buf,i++, vc(15));
7064 break;
7065 }
7066
7067 bool undercombo = false, warpa = false, warpb = false, warpc = false, warpd = false, warpr = false;
7068
7069 word num_ffcs = Map.CurrScr()->numFFC();
7070 for(int32_t c=0; c<176+128+1+num_ffcs; ++c)
7071 {
7072 // Checks both combos, secret combos, undercombos and FFCs
7073 //Fixme:
7074 int32_t ctype =
7075 combobuf[vbound(
7076 (c>=305 ? Map.CurrScr()->ffcs[c-305].data :
7077 c>=304 ? Map.CurrScr()->undercombo :
7078 c>=176 ? Map.CurrScr()->secretcombo[c-176] :
7079 !Map.CurrScr()->valid ? 0 : // Sanity check: does room combo data exist?
7080 Map.CurrScr()->data[c]
7081 ), 0, MAXCOMBOS-1)].type;
7082
7083 if(!undercombo && integrityBoolUnderCombo(Map.CurrScr(),ctype))
7084 {
7085 undercombo = true;
7086 show_screen_error("Under Combo is combo 0",i++, vc(7));
7087 }
7088
7089 // Tile Warp types
7090 switch(ctype)
7091 {
7092 case cSAVE:
7093 case cSAVE2:
7094 if(!savecombo)
7095 {
7096 savecombo = true;
7097
7098 if(integrityBoolSaveCombo(Map.CurrScr(),ctype))
7099 show_screen_error("Save Screen",i++, vc(15));
7100 else
7101 show_screen_error("Save-Continue Screen",i++, vc(15));
7102 }
7103
7104 break;
7105
7106 case cSTAIRR:
7107 case cPITR:
7108 case cSWARPR:
7109 if(!warpr && (Map.CurrScr()->tilewarptype[0]==wtCAVE || Map.CurrScr()->tilewarptype[1]==wtCAVE ||
7110 Map.CurrScr()->tilewarptype[2]==wtCAVE || Map.CurrScr()->tilewarptype[3]==wtCAVE))
7111 {
7112 warpr = true;
7113 show_screen_error("Random Tile Warp contains Cave/Item Cellar",i++, vc(7));
7114 }
7115
7116 break;
7117
7118 case cCAVED:
7119 case cPITD:
7120 case cSTAIRD:
7121 case cCAVE2D:
7122 case cSWIMWARPD:
7123 case cDIVEWARPD:
7124 case cSWARPD:
7125 if(!warpd)
7126 {
7127 warpd = true;
7128 tile_warp_notification(3,buf);
7129 show_screen_error(buf,i++, vc(15));
7130 }
7131
7132 break;
7133
7134 case cCAVEC:
7135 case cPITC:
7136 case cSTAIRC:
7137 case cCAVE2C:
7138 case cSWIMWARPC:
7139 case cDIVEWARPC:
7140 case cSWARPC:
7141 if(!warpc)
7142 {
7143 warpc = true;
7144 tile_warp_notification(2,buf);
7145 show_screen_error(buf,i++, vc(15));
7146 }
7147
7148 break;
7149
7150 case cCAVEB:
7151 case cPITB:
7152 case cSTAIRB:
7153 case cCAVE2B:
7154 case cSWIMWARPB:
7155 case cDIVEWARPB:
7156 case cSWARPB:
7157 if(!warpb)
7158 {
7159 warpb = true;
7160 tile_warp_notification(1,buf);
7161 show_screen_error(buf,i++, vc(15));
7162 }
7163
7164 break;
7165
7166 case cCAVE:
7167 case cPIT:
7168 case cSTAIR:
7169 case cCAVE2:
7170 case cSWIMWARP:
7171 case cDIVEWARP:
7172 case cSWARPA:
7173 if(!warpa)
7174 {
7175 warpa = true;
7176 tile_warp_notification(0,buf);
7177 show_screen_error(buf,i++, vc(15));
7178 }
7179
7180 break;
7181 }
7182 }
7183
7184 int32_t sidewarpnotify = 0;
7185
7186 if(Map.CurrScr()->flags2&wfUP)
7187 {
7188 side_warp_notification(Map.CurrScr()->sidewarpindex&3,0,buf);
7189 show_screen_error(buf,i++, vc(15));
7190 sidewarpnotify|=(1<<(Map.CurrScr()->sidewarpindex&3));
7191 }
7192
7193 if(Map.CurrScr()->flags2&wfDOWN)
7194 {
7195 side_warp_notification((Map.CurrScr()->sidewarpindex>>2)&3,1,buf);
7196 show_screen_error(buf,i++, vc(15));
7197 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>2)&3));
7198 }
7199
7200 if(Map.CurrScr()->flags2&wfLEFT)
7201 {
7202 side_warp_notification((Map.CurrScr()->sidewarpindex>>4)&3,2,buf);
7203 show_screen_error(buf,i++, vc(15));
7204 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>4)&3));
7205 }
7206
7207 if(Map.CurrScr()->flags2&wfRIGHT)
7208 {
7209 side_warp_notification((Map.CurrScr()->sidewarpindex>>6)&3,3,buf);
7210 show_screen_error(buf,i++, vc(15));
7211 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>6)&3));
7212 }
7213
7214 if(!(sidewarpnotify&1) && Map.CurrScr()->timedwarptics)
7215 {
7216 side_warp_notification(0,4,buf); // Timed Warp
7217 show_screen_error(buf,i++, vc(15));
7218 }
7219
7220 // Now for errors
7221 if((Map.CurrScr()->flags4&fSAVEROOM) && !savecombo) show_screen_error("Save Point->Continue Here, but no Save Point combo?",i++, vc(14));
7222
7223 if(integrityBoolEnemiesItem(Map.CurrScr())) show_screen_error("Enemies->Item, but no enemies",i++, vc(7));
7224
7225 if(integrityBoolEnemiesSecret(Map.CurrScr())) show_screen_error("Enemies->Secret, but no enemies",i++, vc(7));
7226
7227 if(integrityBoolGuyNoString(Map.CurrScr())) show_screen_error("Non-Fairy Guy, but String is (none)",i++, vc(14));
7228
7229 if(integrityBoolRoomNoGuy(Map.CurrScr())) show_screen_error("Guy is (none)",i++, vc(14));
7230
7231 if(integrityBoolRoomNoString(Map.CurrScr())) show_screen_error("String is (none)",i++, vc(14));
7232
7233 if(integrityBoolRoomNoGuyNoString(Map.CurrScr())) show_screen_error("Guy and String are (none)",i++, vc(14));
7234 }
7235
7236 if(zoom_delay)
7237 draw_screenunit(rSCRMAP,flags);
7238
7239
7240 if(flags&rCLEAR)
7241 {
7242 //Draw the whole gui
7243 blit(menu1,screen,0,0,0,0,zq_screen_w,zq_screen_h);
7244 }
7245 else
7246 {
7247 blit(menu1,screen,0,16,0,16,zq_screen_w,zq_screen_h-16);
7248 blit(menu1,screen,combolist_window.x-64,0,combolist_window.x-64,0,combolist_window.w+64,16);
7249
7250 if(flags&rCOMBO)
7251 blit(menu1,screen,combo_preview.x,combo_preview.y,combo_preview.x,combo_preview.y,combo_preview.w,combo_preview.h);
7252 }
7253
7254 if(earlyret)
7255 return;
7256
7257 //Draw the Main Menu
7258 rectfill(screen,mainbar.x,mainbar.y,mainbar.x+mainbar.w-1,mainbar.y+mainbar.h-1,jwin_pal[jcBOX]);
7259 jwin_draw_frame(screen,mainbar.x,mainbar.y,mainbar.w,mainbar.h,FR_WIN);
7260
7261 FONT* oldfont = font;
7262 font = get_custom_font(CFONT_GUI);
7263
7264 //Drawmode button
7265 draw_text_button(screen,drawmode_btn.x,drawmode_btn.y,drawmode_btn.w,drawmode_btn.h,dm_names[draw_mode],vc(1),vc(14),0,true);
7266 //Compact button
7267 draw_text_button(screen,compactbtn.x, compactbtn.y, compactbtn.w, compactbtn.h, is_compact ? "< Expand" : "> Compact", vc(1),vc(14),0,true);
7268 //Zoom buttons
7269 zoom_in_btn_disabled = num_screens_to_draw == 1;
7270 zoom_out_btn_disabled = num_screens_to_draw == mapscreen_num_screens_to_draw_max;
7271 draw_text_button(screen,zoominbtn.x, zoominbtn.y, zoominbtn.w, zoominbtn.h, "+", vc(1),vc(14),zoom_in_btn_disabled ? D_DISABLED : 0,true);
7272 draw_text_button(screen,zoomoutbtn.x, zoomoutbtn.y, zoomoutbtn.w, zoomoutbtn.h, "-", vc(1),vc(14),zoom_out_btn_disabled ? D_DISABLED : 0,true);
7273
7274 font = oldfont;
7275
7276 d_nbmenu_proc(MSG_DRAW, &dialogs[0], 0);
7277
7278 ComboBrushPause=0;
7279
7280 SCRFIX();
7281 if(update)
7282 custom_vsync();
7283 is_refreshing = refreshing = false;
7284 11 }
7285
7286 12 static int minimap_tooltip_id = ttip_register_id();
7287
7288 void select_scr()
7289 {
7290 if(Map.getCurrMap()>=Map.getMapCount())
7291 return;
7292
7293 int32_t tempcb=ComboBrush;
7294 ComboBrush=0;
7295
7296 size_and_pos const& real_mini = zoomed_minimap ? real_minimap_zoomed : real_minimap;
7297
7298 //scooby
7299 while(gui_mouse_b())
7300 {
7301 int32_t x=gui_mouse_x();
7302 int32_t y=gui_mouse_y();
7303
7304 int32_t ind = real_mini.rectind(x,y);
7305
7306 if(ind>=MAPSCRS)
7307 ind-=16;
7308
7309 if(ind > -1 && ind != Map.getCurrScr())
7310 {
7311 Map.setCurrScr(ind);
7312 }
7313
7314 custom_vsync();
7315 refresh(rALL);
7316 }
7317
7318 ComboBrush=tempcb;
7319 }
7320
7321 void clear_cpool()
7322 {
7323 for(int32_t i=0; i<MAXFAVORITECOMBOS; ++i)
7324 {
7325 pool_combos[i].clear();
7326 }
7327 pool_dirty = true;
7328 }
7329
7330 bool select_favorite()
7331 {
7332 int32_t tempcb=ComboBrush;
7333 ComboBrush=0;
7334 bool valid=false;
7335
7336 while(gui_mouse_b())
7337 {
7338 valid=false;
7339 int32_t x=gui_mouse_x();
7340
7341 if(x<favorites_list.x)
7342 x=favorites_list.x;
7343
7344 if(x>favorites_list.x+(favorites_list.w*favorites_list.xscale)-1)
7345 x=favorites_list.x+(favorites_list.w*favorites_list.xscale)-1;
7346
7347 int32_t y=gui_mouse_y();
7348
7349 if(y<favorites_list.y)
7350 y=favorites_list.y;
7351
7352 if(y>favorites_list.y+(favorites_list.h*favorites_list.yscale)-1)
7353 y=favorites_list.y+(favorites_list.h*favorites_list.yscale)-1;
7354
7355 int32_t tempc=(((y-favorites_list.y)/favorites_list.yscale)*FAVORITECOMBO_PER_ROW)+((x-favorites_list.x)/favorites_list.xscale) + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
7356
7357 if(tempc >= MAXFAVORITECOMBOS)
7358 {
7359 //Nothing, invalid
7360 }
7361 else
7362 {
7363 if(favorite_combos[tempc]!=-1)
7364 {
7365 switch(favorite_combo_modes[tempc])
7366 {
7367 case dm_alias:
7368 draw_mode = dm_alias;
7369 combo_apos = favorite_combos[tempc];
7370 break;
7371 case dm_cpool:
7372 draw_mode = dm_cpool;
7373 combo_pool_pos = favorite_combos[tempc];
7374 break;
7375 case dm_auto:
7376 draw_mode = dm_auto;
7377 combo_auto_pos = favorite_combos[tempc];
7378 break;
7379 default:
7380 draw_mode = dm_normal;
7381 Combo = favorite_combos[tempc];
7382 }
7383 if(AutoBrush)
7384 BrushWidth = BrushHeight = 1;
7385 valid=true;
7386 fix_drawing_mode_menu();
7387 }
7388 }
7389
7390 custom_vsync();
7391 refresh(rALL);
7392 }
7393
7394 ComboBrush=tempcb;
7395 return valid;
7396 }
7397
7398 void select_combo(int32_t clist)
7399 {
7400 current_combolist=clist;
7401 int32_t tempcb=ComboBrush;
7402 ComboBrush=0;
7403
7404 int autobrush_cx = -1, autobrush_cy = -1;
7405 int autobrush_first = First[current_combolist];
7406 auto& curlist = combolist[current_combolist];
7407 AutoBrushRevert = (key[KEY_ALT]||key[KEY_ALTGR]);
7408 while(gui_mouse_b())
7409 {
7410 int32_t x=gui_mouse_x();
7411
7412 if(x<curlist.x)
7413 x=curlist.x;
7414
7415 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7416 x=curlist.x+(curlist.w*curlist.xscale)-1;
7417
7418 int32_t y=gui_mouse_y();
7419
7420 if(y<curlist.y)
7421 y=curlist.y;
7422
7423 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7424 y=curlist.y+(curlist.h*curlist.yscale)-1;
7425
7426 int cx = ((x-curlist.x)/curlist.xscale), cy = ((y-curlist.y)/curlist.yscale);
7427 if(AutoBrush)
7428 {
7429 if(autobrush_cx < 0)
7430 {
7431 autobrush_cx = cx;
7432 autobrush_cy = cy;
7433 }
7434 BrushWidth = vbound(abs(autobrush_cx-cx)+1,1,16);
7435 BrushHeight = vbound(abs(autobrush_cy-cy)+1,1,11);
7436 cx = std::min(autobrush_cx,cx);
7437 cy = std::min(autobrush_cy,cy);
7438 }
7439 Combo=(cy*curlist.w)+cx+First[current_combolist];
7440 custom_vsync();
7441 refresh(rALL);
7442 if(AutoBrush) //Prevent any scrolling
7443 First[current_combolist] = autobrush_first;
7444 }
7445 if(key[KEY_ALT]||key[KEY_ALTGR])
7446 AutoBrushRevert = true;
7447 position_mouse_z(0);
7448 ComboBrush=tempcb;
7449 }
7450
7451 void select_comboa(int32_t clist)
7452 {
7453 current_comboalist=clist;
7454 int32_t tempcb=ComboBrush;
7455 ComboBrush=0;
7456 alias_cset_mod=0;
7457
7458 auto& curlist = comboaliaslist[current_comboalist];
7459 while(gui_mouse_b())
7460 {
7461 int32_t x=gui_mouse_x();
7462
7463 if(x<curlist.x)
7464 x=curlist.x;
7465
7466 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7467 x=curlist.x+(curlist.w*curlist.xscale)-1;
7468
7469 int32_t y=gui_mouse_y();
7470
7471 if(y<curlist.y)
7472 y=curlist.y;
7473
7474 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7475 y=curlist.y+(curlist.h*curlist.yscale)-1;
7476
7477 combo_apos=(((y-curlist.y)/curlist.yscale)*curlist.w)+((x-curlist.x)/curlist.xscale)+combo_alistpos[current_comboalist];
7478 custom_vsync();
7479 refresh(rALL);
7480 }
7481
7482 ComboBrush=tempcb;
7483 }
7484
7485 void select_combop(int32_t clist)
7486 {
7487 current_cpoollist=clist;
7488 int32_t tempcb=ComboBrush;
7489 ComboBrush=0;
7490
7491 auto& curlist = comboaliaslist[current_cpoollist];
7492 while(gui_mouse_b())
7493 {
7494 int32_t x=gui_mouse_x();
7495
7496 if(x<curlist.x) x=curlist.x;
7497
7498 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7499 x=curlist.x+(curlist.w*curlist.xscale)-1;
7500
7501 int32_t y=gui_mouse_y();
7502
7503 if(y<curlist.y) y=curlist.y;
7504
7505 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7506 y=curlist.y+(curlist.h*curlist.yscale)-1;
7507
7508 combo_pool_pos=(((y-curlist.y)/curlist.yscale)*curlist.w)+((x-curlist.x)/curlist.xscale)+combo_pool_listpos[current_cpoollist];
7509 custom_vsync();
7510 refresh(rALL);
7511 }
7512
7513 ComboBrush=tempcb;
7514 }
7515
7516 void select_autocombo(int32_t clist)
7517 {
7518 current_cautolist = clist;
7519 int32_t tempcb = ComboBrush;
7520 ComboBrush = 0;
7521
7522 auto& curlist = comboaliaslist[current_cautolist];
7523 while (gui_mouse_b())
7524 {
7525 int32_t x = gui_mouse_x();
7526
7527 if (x < curlist.x) x = curlist.x;
7528
7529 if (x > curlist.x + (curlist.w * curlist.xscale) - 1)
7530 x = curlist.x + (curlist.w * curlist.xscale) - 1;
7531
7532 int32_t y = gui_mouse_y();
7533
7534 if (y < curlist.y) y = curlist.y;
7535
7536 if (y > curlist.y + (curlist.h * curlist.yscale) - 1)
7537 y = curlist.y + (curlist.h * curlist.yscale) - 1;
7538
7539 combo_auto_pos = (((y - curlist.y) / curlist.yscale) * curlist.w) + ((x - curlist.x) / curlist.xscale) + combo_auto_listpos[current_cautolist];
7540 cauto_height = combo_autos[combo_auto_pos].getArg() + 1;
7541 custom_vsync();
7542 refresh(rALL);
7543 }
7544
7545 ComboBrush = tempcb;
7546 }
7547
7548 void update_combobrush()
7549 {
7550 clear_bitmap(brushbmp);
7551
7552 if(draw_mode==dm_alias)
7553 {
7554 //int32_t count=(combo_aliases[combo_apos].width+1)*(combo_aliases[combo_apos].height+1)*(comboa_lmasktotal(combo_aliases[combo_apos].layermask));
7555 for(int32_t z=0; z<=comboa_lmasktotal(combo_aliases[combo_apos].layermask); z++)
7556 {
7557 for(int32_t y=0; y<=combo_aliases[combo_apos].height; y++)
7558 {
7559 for(int32_t x=0; x<=combo_aliases[combo_apos].width; x++)
7560 {
7561 int32_t position = ((y*(combo_aliases[combo_apos].width+1))+x)+((combo_aliases[combo_apos].width+1)*(combo_aliases[combo_apos].height+1)*z);
7562
7563 if(combo_aliases[combo_apos].combos[position])
7564 {
7565 if(z==0)
7566 {
7567 putcombo(brushbmp,x<<4,y<<4,combo_aliases[combo_apos].combos[position],wrap(combo_aliases[combo_apos].csets[position]+alias_cset_mod, 0, 13));
7568 }
7569 else
7570 {
7571 overcombo(brushbmp,x<<4,y<<4,combo_aliases[combo_apos].combos[position],wrap(combo_aliases[combo_apos].csets[position]+alias_cset_mod, 0, 13));
7572 }
7573 }
7574 }
7575 }
7576 }
7577
7578 int xoff = 6, yoff = 6;
7579 if(FloatBrush) // Offset the floating pixels, so the 'x' appears centered on the combo still -Em
7580 {
7581 xoff += 2;
7582 yoff += 2;
7583 }
7584 if(alias_origin & 1) // Right-align
7585 xoff += combo_aliases[combo_apos].width*16;
7586 if(alias_origin & 2) // Bottom-align
7587 yoff += combo_aliases[combo_apos].height*16;
7588
7589 textprintf_shadowed_ex(brushbmp, get_zc_font(font_sfont), xoff, yoff, vc(15), vc(0), -1, "x");
7590 }
7591 else if(draw_mode != dm_cpool)
7592 {
7593 int32_t cid = combobrushoverride > -1 ? combobrushoverride : Combo;
7594 int32_t c = 0;
7595
7596 for(int32_t i=0; i<256; i++)
7597 {
7598 if(unsigned(cid+c) >= MAXCOMBOS) break;
7599 if(((i%COMBOS_PER_ROW)<BrushWidth)&&((i/COMBOS_PER_ROW)<BrushHeight))
7600 {
7601 put_combo(brushbmp,(i%COMBOS_PER_ROW)<<4,(i/COMBOS_PER_ROW)<<4,cid+c,CSet,Flags&(cFLAGS|cWALK),0);
7602 }
7603
7604 if(((cid+c)&3)==3)
7605 c+=48;
7606
7607 ++c;
7608
7609 if((i%COMBOS_PER_ROW)==(COMBOS_PER_ROW-1))
7610 c-=256;
7611 }
7612 }
7613 }
7614
7615 byte relational_source_grid[256]=
7616 {
7617 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7618 16, 16, 17, 17, 18, 18, 19, 19, 16, 16, 17, 17, 18, 18, 19, 19,
7619 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23,
7620 24, 24, 24, 24, 25, 25, 25, 25, 24, 24, 24, 24, 25, 25, 25, 25,
7621 26, 27, 26, 27, 26, 27, 26, 27, 28, 29, 28, 29, 28, 29, 28, 29,
7622 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
7623 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32,
7624 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
7625 34, 35, 36, 37, 34, 35, 36, 37, 34, 35, 36, 37, 34, 35, 36, 37,
7626 38, 38, 39, 39, 38, 38, 39, 39, 38, 38, 39, 39, 38, 38, 39, 39,
7627 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
7628 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
7629 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43,
7630 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
7631 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
7632 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46
7633 };
7634
7635 static void draw_autocombo(ComboPosition combo_pos, bool rclick, bool pressframe = false)
7636 {
7637 combo_auto &ca = combo_autos[combo_auto_pos];
7638 int screen = Map.getScreenForPosition(combo_pos);
7639 int pos = combo_pos.truncate();
7640
7641 if (ca.valid())
7642 {
7643 switch (ca.getType())
7644 {
7645 case AUTOCOMBO_BASIC:
7646 {
7647 AutoPattern::autopattern_basic ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7648 if (rclick)
7649 ap.erase(screen, pos);
7650 else
7651 ap.execute(screen, pos);
7652 break;
7653 }
7654 case AUTOCOMBO_Z1:
7655 {
7656 AutoPattern::autopattern_flatmtn ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7657 if (rclick)
7658 ap.erase(screen, pos);
7659 else
7660 ap.execute(screen, pos);
7661 break;
7662 }
7663 case AUTOCOMBO_FENCE:
7664 {
7665 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7666 if (rclick)
7667 ap.erase(screen, pos);
7668 else
7669 ap.execute(screen, pos);
7670 break;
7671 }
7672 case AUTOCOMBO_Z4:
7673 {
7674 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7675 if (rclick)
7676 ap.erase(screen, pos);
7677 else
7678 ap.execute(screen, pos);
7679 break;
7680 }
7681 case AUTOCOMBO_RELATIONAL:
7682 {
7683 AutoPattern::autopattern_relational ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7684 if (rclick)
7685 ap.erase(screen, pos);
7686 else
7687 ap.execute(screen, pos);
7688 break;
7689 }
7690 case AUTOCOMBO_DGNCARVE:
7691 {
7692 AutoPattern::autopattern_dungeoncarve ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7693 if (rclick)
7694 ap.erase(screen, pos);
7695 else
7696 ap.execute(screen, pos);
7697 break;
7698 }
7699 case AUTOCOMBO_DOR:
7700 {
7701 AutoPattern::autopattern_dormtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7702 if (rclick)
7703 ap.erase(screen, pos);
7704 else
7705 ap.execute(screen, pos);
7706 break;
7707 }
7708 case AUTOCOMBO_TILING:
7709 {
7710 if (pressframe && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7711 {
7712 int32_t x = (screen % 16) * 16 + (pos % 16);
7713 int32_t y = (screen / 16) * 11 + (pos / 16);
7714 byte w = (ca.getArg() & 0xF) + 1;
7715 byte h = ((ca.getArg() >> 4) & 0xF) + 1;
7716 ca.setOffsets(x % w, y % h);
7717 }
7718 AutoPattern::autopattern_tiling ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7719 if (rclick)
7720 ap.erase(screen, pos);
7721 else
7722 ap.execute(screen, pos);
7723 break;
7724 }
7725 case AUTOCOMBO_REPLACE:
7726 {
7727 AutoPattern::autopattern_replace ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7728 if (rclick)
7729 ap.erase(screen, pos);
7730 else
7731 ap.execute(screen, pos);
7732 break;
7733 }
7734 case AUTOCOMBO_DENSEFOREST:
7735 {
7736 if (pressframe && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7737 {
7738 int32_t x = (screen % 16) * 16 + (pos % 16);
7739 int32_t y = (screen / 16) * 11 + (pos / 16);
7740 ca.setOffsets(x % 2, y % 2);
7741 }
7742 AutoPattern::autopattern_denseforest ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7743 if (rclick)
7744 ap.erase(screen, pos);
7745 else
7746 ap.execute(screen, pos);
7747 break;
7748 }
7749 case AUTOCOMBO_EXTEND:
7750 {
7751 if (CHECK_CTRL_CMD)
7752 break;
7753 AutoPattern::autopattern_extend ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7754 if (rclick)
7755 ap.erase(screen, pos);
7756 else
7757 ap.execute(screen, pos);
7758 break;
7759 }
7760 }
7761 }
7762 else
7763 {
7764 ca.updateValid();
7765 if(!ca.valid())
7766 InfoDialog("Notice", "The autocombo you're trying to use is invalid. Reason:"
7767 + ca.getInvalidReason()).show();
7768 }
7769 }
7770
7771 static void draw_autocombo_command(ComboPosition combo_pos, int32_t cmd = 0, int32_t arg = 0)
7772 {
7773 combo_auto ca = combo_autos[combo_auto_pos];
7774 int screen = Map.getScreenForPosition(combo_pos);
7775 int pos = combo_pos.truncate();
7776
7777 if (ca.valid())
7778 {
7779 switch (ca.getType())
7780 {
7781 case AUTOCOMBO_FENCE:
7782 {
7783 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7784 ap.flip_all_connected(screen, pos, 2048);
7785 break;
7786 }
7787 case AUTOCOMBO_Z4:
7788 {
7789 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7790 switch (cmd)
7791 {
7792 case 0: // Flip
7793 ap.flip_all_connected(screen, pos, 2048);
7794 break;
7795 case 1: // Grow
7796 ap.resize_connected(screen, pos, 2048, vbound(arg, 1, 9));
7797 break;
7798 }
7799 }
7800 }
7801 }
7802 }
7803
7804 static int32_t get_autocombo_floating_cid(ComboPosition combo_pos, bool clicked)
7805 {
7806 combo_auto& ca = combo_autos[combo_auto_pos];
7807 int screen = Map.getScreenForPosition(combo_pos);
7808 int pos = combo_pos.truncate();
7809 int cid = 0;
7810
7811 if (ca.valid() && Map.isValidPosition(mouse_combo_pos))
7812 {
7813 switch (ca.getType())
7814 {
7815 case AUTOCOMBO_BASIC:
7816 {
7817 AutoPattern::autopattern_basic ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7818 cid = ap.get_floating_cid(screen, pos);
7819 break;
7820 }
7821
7822 case AUTOCOMBO_Z1:
7823 {
7824 AutoPattern::autopattern_flatmtn ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7825 cid = ap.get_floating_cid(screen, pos);
7826 break;
7827 }
7828 case AUTOCOMBO_FENCE:
7829 {
7830 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7831 cid = ap.get_floating_cid(screen, pos);
7832 break;
7833 }
7834 case AUTOCOMBO_Z4:
7835 {
7836 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7837 cid = ap.get_floating_cid(screen, pos);
7838 break;
7839 }
7840 case AUTOCOMBO_RELATIONAL:
7841 {
7842 AutoPattern::autopattern_relational ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7843 cid = ap.get_floating_cid(screen, pos);
7844 break;
7845 }
7846 case AUTOCOMBO_DGNCARVE:
7847 {
7848 AutoPattern::autopattern_dungeoncarve ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7849 cid = ap.get_floating_cid(screen, pos);
7850 break;
7851 }
7852 case AUTOCOMBO_DOR:
7853 {
7854 AutoPattern::autopattern_dormtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7855 cid = ap.get_floating_cid(screen, pos);
7856 break;
7857 }
7858 case AUTOCOMBO_TILING:
7859 {
7860 std::pair<byte, byte> offs = ca.getOffsets();
7861 if (!clicked && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7862 {
7863 int32_t x = (screen % 16) * 16 + (pos % 16);
7864 int32_t y = (screen / 16) * 11 + (pos / 16);
7865 byte w = (ca.getArg() & 0xF) + 1;
7866 byte h = ((ca.getArg() >> 4) & 0xF) + 1;
7867 offs.first = (x % w);
7868 offs.second = (y % h);
7869 }
7870 AutoPattern::autopattern_tiling ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7871 cid = ap.get_floating_cid(screen, pos);
7872 break;
7873 }
7874 case AUTOCOMBO_REPLACE:
7875 {
7876 AutoPattern::autopattern_replace ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7877 cid = ap.get_floating_cid(screen, pos);
7878 break;
7879 }
7880 case AUTOCOMBO_DENSEFOREST:
7881 {
7882 AutoPattern::autopattern_denseforest ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7883 cid = ap.get_floating_cid(screen, pos);
7884 break;
7885 }
7886 case AUTOCOMBO_EXTEND:
7887 {
7888 AutoPattern::autopattern_extend ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7889 cid = ap.get_floating_cid(screen, pos);
7890 break;
7891 }
7892 }
7893 }
7894 return cid;
7895 }
7896
7897 void change_autocombo_height(int32_t change)
7898 {
7899 bool can_change = false;
7900 if (draw_mode == dm_auto)
7901 {
7902 combo_auto ca = combo_autos[combo_auto_pos];
7903 switch (ca.getType())
7904 {
7905 case AUTOCOMBO_Z4:
7906 can_change = true;
7907 [[fallthrough]];
7908 case AUTOCOMBO_DOR:
7909 break;
7910 default:
7911 return;
7912 }
7913 }
7914 else
7915 return;
7916
7917 int32_t x = gui_mouse_x();
7918 int32_t y = gui_mouse_y();
7919 double startx = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0);
7920 double starty = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0);
7921 int32_t startxint = mapscreen_x + (showedges ? int32_t(16 * mapscreen_single_scale) : 0);
7922 int32_t startyint = mapscreen_y + (showedges ? int32_t(16 * mapscreen_single_scale) : 0);
7923 ComboPosition pos = get_mapscreen_mouse_combo_pos();
7924
7925 if (can_change && isinRect(x, y, startxint, startyint, int32_t(startx + (256 * mapscreen_single_scale) - 1), int32_t(starty + (176 * mapscreen_single_scale) - 1)))
7926 {
7927 Map.StartListCommand();
7928 draw_autocombo_command(pos, 1, cauto_height + change);
7929 Map.FinishListCommand();
7930 }
7931 cauto_height = vbound(cauto_height + change, 1, 9);
7932 }
7933
7934 void draw(bool justcset)
7935 {
7936 combo_pool const& pool = combo_pools[combo_pool_pos];
7937 if(draw_mode == dm_cpool && !pool.valid())
7938 return;
7939 saved=false;
7940
7941 refresh(rMAP+rSCRMAP);
7942 ComboPosition last_pos = {-1, -1};
7943
7944 Map.StartListCommand();
7945 bool pressframe = true;
7946 while(gui_mouse_b())
7947 {
7948 int32_t x=gui_mouse_x();
7949 int32_t y=gui_mouse_y();
7950 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
7951 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
7952 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
7953 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
7954 int num_combos_width = 16 * Map.getViewSize();
7955 int num_combos_height = 11 * Map.getViewSize();
7956
7957 if(isinRect(x,y,startxint,startyint,int32_t(startx+(256*mapscreen_screenunit_scale)-1),int32_t(starty+(176*mapscreen_screenunit_scale)-1)))
7958 {
7959 int32_t cxstart=(x-startx)/(16*mapscreen_single_scale);
7960 int32_t cystart=(y-starty)/(16*mapscreen_single_scale);
7961 ComboPosition combo_start = {cxstart, cystart};
7962 if (pressframe)
7963 {
7964 last_pos = combo_start;
7965 }
7966 else if (combo_start == last_pos)
7967 {
7968 custom_vsync();
7969 refresh(rALL);
7970 continue;
7971 }
7972 else if(draw_mode == dm_auto)
7973 {
7974 // TODO: support when zoomed out.
7975 if (combo_autos[combo_auto_pos].getType() == AUTOCOMBO_FENCE || combo_autos[combo_auto_pos].getType() == AUTOCOMBO_Z4)
7976 {
7977 // Don't allow moving the brush at anything but cardinal directions while in these modes
7978 bool did_diag = std::abs(combo_start.x - last_pos.x) == 1 && std::abs(combo_start.y - last_pos.y) == 1;
7979
7980 if (did_diag)
7981 {
7982 int32_t oldx = last_pos.x;
7983 int32_t oldy = last_pos.y;
7984 int32_t cx = (oldx * 16 * mapscreen_single_scale) + 8;
7985 int32_t cy = (oldy * 16 * mapscreen_single_scale) + 8;
7986 int32_t nx = x - startxint;
7987 int32_t ny = y - startyint;
7988 if (std::abs(nx - cx) < std::abs(ny - cy))
7989 {
7990 oldy = vbound(oldy + ((ny - cy) < 0 ? -1 : 1), 0, 11);
7991 }
7992 else
7993 {
7994 oldx = vbound(oldx + ((nx - cx) < 0 ? -1 : 1), 0, 15);
7995 }
7996 combo_start = {oldx, oldy};
7997 }
7998 }
7999 }
8000 last_pos = combo_start;
8001
8002 switch(draw_mode)
8003 {
8004 case dm_normal:
8005 {
8006 int32_t cc=Combo;
8007
8008 for(int32_t cy=0; cy+cystart<num_combos_height&&cy<BrushHeight; cy++)
8009 {
8010 for(int32_t cx=0; cx+cxstart<num_combos_width&&cx<BrushWidth; cx++)
8011 {
8012 auto pos = combo_start + ComboPosition{cx, cy};
8013 cc=Combo + cx + cy*4;
8014 Map.DoSetComboCommand(pos, justcset ? -1 : cc, CSet);
8015 }
8016 }
8017
8018 update_combobrush();
8019 }
8020 break;
8021 case dm_cpool:
8022 {
8023 int32_t cid = Combo;
8024 int8_t cs = CSet;
8025 pool.pick(cid,cs);
8026 Map.DoSetComboCommand(combo_start, justcset ? -1 : cid, cs);
8027
8028 update_combobrush();
8029 }
8030 break;
8031
8032 case dm_alias:
8033 {
8034 combo_alias *combo = &combo_aliases[combo_apos];
8035 if(!combo->layermask)
8036 {
8037 int32_t ox=0, oy=0;
8038
8039 switch(alias_origin)
8040 {
8041 case 0:
8042 ox=0;
8043 oy=0;
8044 break;
8045
8046 case 1:
8047 ox=(combo->width);
8048 oy=0;
8049 break;
8050
8051 case 2:
8052 ox=0;
8053 oy=(combo->height);
8054 break;
8055
8056 case 3:
8057 ox=(combo->width);
8058 oy=(combo->height);
8059 break;
8060 }
8061
8062 for(int32_t cy=0; cy-oy+cystart<num_combos_height&&cy<=combo->height; cy++)
8063 {
8064 for(int32_t cx=0; cx-ox+cxstart<num_combos_width&&cx<=combo->width; cx++)
8065 {
8066 if((cx+cxstart-ox>=0)&&(cy+cystart-oy>=0))
8067 {
8068 int32_t p=(cy*(combo->width+1))+cx;
8069
8070 if(combo->combos[p])
8071 {
8072 auto pos = combo_start + ComboPosition{cx - ox, cy - oy};
8073 Map.DoSetComboCommand(pos, combo->combos[p], wrap(combo->csets[p]+alias_cset_mod, 0, 13));
8074 }
8075 }
8076 }
8077 }
8078 }
8079 else
8080 {
8081 int32_t laypos = 0;
8082 int32_t ox=0, oy=0;
8083
8084 switch(alias_origin)
8085 {
8086 case 0:
8087 ox=0;
8088 oy=0;
8089 break;
8090
8091 case 1:
8092 ox=(combo->width);
8093 oy=0;
8094 break;
8095
8096 case 2:
8097 ox=0;
8098 oy=(combo->height);
8099 break;
8100
8101 case 3:
8102 ox=(combo->width);
8103 oy=(combo->height);
8104 break;
8105 }
8106
8107 for(int32_t cz=0; cz<7; cz++)
8108 {
8109 if (cz > 0 && !(combo->layermask & (1<<(cz-1))))
8110 continue;
8111
8112 if (cz > 0)
8113 laypos++;
8114
8115 for(int32_t cy=0; cy-oy+cystart<num_combos_height&&cy<=combo->height; cy++)
8116 {
8117 for(int32_t cx=0; cx-ox+cxstart<num_combos_width&&cx<=combo->width; cx++)
8118 {
8119 if((cx+cxstart-ox>=0)&&(cy+cystart-oy>=0))
8120 {
8121 int32_t p=((cy*(combo->width+1))+cx)+((combo->width+1)*(combo->height+1)*laypos);
8122
8123 if (combo->combos[p])
8124 {
8125 auto pos = combo_start + ComboPosition{cx - ox, cy - oy};
8126 if(cz > 0 && Map.Scr(pos)->layermap[cz - 1] == 0)
8127 continue;
8128 int prev = CurrentLayer;
8129 CurrentLayer = cz;
8130 Map.DoSetComboCommand(pos, combo->combos[p], wrap(combo->csets[p]+alias_cset_mod, 0, 13));
8131 CurrentLayer = prev;
8132 }
8133 }
8134 }
8135 }
8136 }
8137 }
8138
8139 break;
8140 }
8141
8142 case dm_auto:
8143 {
8144 draw_autocombo(combo_start, gui_mouse_b() & 2, pressframe);
8145
8146 combobrushoverride = get_autocombo_floating_cid(combo_start, true);
8147 update_combobrush();
8148 }
8149 }
8150 }
8151 pressframe = false;
8152
8153 custom_vsync();
8154 refresh(rALL);
8155 }
8156
8157 Map.FinishListCommand();
8158 if(AutoBrushRevert)
8159 {
8160 AutoBrushRevert = false;
8161 BrushWidth = 1;
8162 BrushHeight = 1;
8163 }
8164 }
8165
8166 static void replace(ComboPosition start)
8167 {
8168 int32_t cid = Combo;
8169 int8_t cs = CSet;
8170 combo_pool const& pool = combo_pools[combo_pool_pos];
8171 if(draw_mode == dm_cpool && !pool.valid())
8172 return;
8173
8174 int c = start.truncate();
8175 mapscr* scr = Map.Scr(start, CurrentLayer);
8176 if (!scr) return;
8177
8178 int num_combos_width = 16 * Map.getViewSize();
8179 int num_combos_height = 11 * Map.getViewSize();
8180 int targetcombo = scr->data[c];
8181 int targetcset = scr->cset[c];
8182
8183 saved = false;
8184 Map.StartListCommand();
8185 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
8186 {
8187 for (int x = 0; x < num_combos_width; x++)
8188 {
8189 for (int y = 0; y < num_combos_height; y++)
8190 {
8191 ComboPosition pos = {x, y};
8192 int c = pos.truncate();
8193 mapscr* scr = Map.Scr(pos, CurrentLayer);
8194 if (!scr)
8195 continue;
8196
8197 if ((scr->cset[c]) == targetcset)
8198 {
8199 if(draw_mode == dm_cpool)
8200 pool.pick(cid,cs);
8201 Map.DoSetComboCommand(pos, -1, cs);
8202 }
8203 }
8204 }
8205 }
8206 else
8207 {
8208 for (int x = 0; x < num_combos_width; x++)
8209 {
8210 for (int y = 0; y < num_combos_height; y++)
8211 {
8212 ComboPosition pos = {x, y};
8213 int c = pos.truncate();
8214 mapscr* scr = Map.Scr(pos, CurrentLayer);
8215 if (!scr)
8216 continue;
8217
8218 if(((scr->data[c])==targetcombo) &&
8219 ((scr->cset[c])==targetcset))
8220 {
8221 if(draw_mode == dm_cpool)
8222 pool.pick(cid,cs);
8223 Map.DoSetComboCommand(pos, cid, cs);
8224 }
8225 }
8226 }
8227 }
8228 Map.FinishListCommand();
8229
8230 refresh(rMAP);
8231 }
8232
8233 static void draw_block(ComboPosition start, int32_t w, int32_t h)
8234 {
8235 int32_t cid = Combo;
8236 int8_t cs = CSet;
8237 if(draw_mode == dm_cpool)
8238 {
8239 combo_pool const& pool = combo_pools[combo_pool_pos];
8240 if(!pool.pick(cid,cs)) return;
8241 }
8242
8243 mapscr* scr = Map.Scr(start, CurrentLayer);
8244 if (!scr) return;
8245
8246 saved = false;
8247 Map.StartListCommand();
8248 for (int32_t y=0; y < h && y < 11*Map.getViewSize(); y++)
8249 for (int32_t x=0; x < w && x < 16*Map.getViewSize(); x++)
8250 {
8251 Map.DoSetComboCommand(start + ComboPosition{x, y}, cid+(y*4)+x, cs);
8252 }
8253
8254 Map.FinishListCommand();
8255 refresh(rMAP+rSCRMAP);
8256 }
8257
8258 static std::vector<ComboPosition> flood_filler(ComboPosition start_pos, bool allow_diagonal, std::function<bool(ComboPosition)> check)
8259 {
8260 std::vector<ComboPosition> seen, queue;
8261
8262 queue.push_back(start_pos);
8263 while (!queue.empty())
8264 {
8265 ComboPosition pos = queue.back();
8266 queue.pop_back();
8267 seen.push_back(pos);
8268
8269 ComboPosition pos2;
8270 #define FLOOD_FILLER_CHECK(dx, dy)\
8271 pos2 = pos + ComboPosition{dx, dy};\
8272 if (std::find(seen.begin(), seen.end(), pos2) == seen.end() && check(pos2))\
8273 queue.push_back(pos2);
8274
8275 FLOOD_FILLER_CHECK(0, 1);
8276 FLOOD_FILLER_CHECK(0, -1);
8277 FLOOD_FILLER_CHECK(1, 0);
8278 FLOOD_FILLER_CHECK(-1, 0);
8279
8280 if (allow_diagonal)
8281 {
8282 FLOOD_FILLER_CHECK(1, 1);
8283 FLOOD_FILLER_CHECK(1, -1);
8284 FLOOD_FILLER_CHECK(-1, 1);
8285 FLOOD_FILLER_CHECK(-1, -1);
8286 }
8287
8288 #undef FLOOD_FILLER_CHECK
8289 }
8290
8291 return seen;
8292 }
8293
8294 static void fill(int32_t targetcombo, int32_t targetcset, ComboPosition start_pos, bool allow_diagonal, bool only_cset)
8295 {
8296 bool rclick = gui_mouse_b() & 2;
8297 bool ignored_combo = false;
8298
8299 mapscr* scr = Map.ScrMakeValid(start_pos, CurrentLayer);
8300 if (!scr)
8301 return;
8302
8303 int num_combos_width = 16 * Map.getViewSize();
8304 int num_combos_height = 11 * Map.getViewSize();
8305
8306 auto combo_positions = flood_filler(start_pos, allow_diagonal, [&](ComboPosition pos){
8307 if (pos.x < 0 || pos.y < 0 || pos.x >= num_combos_width || pos.y >= num_combos_height)
8308 return false;
8309
8310 mapscr* scr = Map.Scr(pos, CurrentLayer);
8311 if (!scr || !scr->is_valid())
8312 return false;
8313
8314 int cid = scr->data[pos.truncate()];
8315 int cset = scr->cset[pos.truncate()];
8316
8317 if (draw_mode == dm_auto)
8318 {
8319 combo_auto const& cauto = combo_autos[combo_auto_pos];
8320
8321 ignored_combo = cauto.isIgnoredCombo(cid);
8322 if (rclick)
8323 {
8324 if (cauto.containsCombo(targetcombo))
8325 {
8326 if (!cauto.containsCombo(cid))
8327 return false;
8328 if (cauto.getType() == AUTOCOMBO_REPLACE && ignored_combo)
8329 return false;
8330 }
8331 else
8332 return false;
8333 }
8334 else
8335 {
8336 if (cid != targetcombo && !ignored_combo)
8337 return false;
8338 if (cauto.getType() == AUTOCOMBO_REPLACE && !ignored_combo)
8339 return false;
8340 }
8341
8342 if (cset != targetcset && !ignored_combo)
8343 return false;
8344 }
8345 else
8346 {
8347 if(!only_cset)
8348 {
8349 if (cid != targetcombo)
8350 return false;
8351 }
8352
8353 if (cset != targetcset)
8354 return false;
8355 }
8356
8357 return true;
8358 });
8359
8360 for (auto& pos : combo_positions)
8361 {
8362 int32_t cid = Combo;
8363 int8_t cs = CSet;
8364
8365 if (draw_mode == dm_cpool)
8366 {
8367 combo_pool const& pool = combo_pools[combo_pool_pos];
8368 if (!pool.pick(cid, cs)) continue;
8369 }
8370 else if (draw_mode == dm_auto)
8371 {
8372 combo_auto const& cauto = combo_autos[combo_auto_pos];
8373 if (!cauto.valid())
8374 continue;
8375 if (!rclick && (cauto.containsCombo(targetcombo) && !ignored_combo))
8376 continue;
8377 if (rclick && cauto.getEraseCombo() == targetcombo)
8378 continue;
8379 }
8380
8381 if (draw_mode == dm_auto)
8382 draw_autocombo(pos, rclick);
8383 else
8384 Map.DoSetComboCommand(pos, only_cset ? -1 : cid, cs);
8385 }
8386 }
8387
8388 static void fill_flag(int32_t targetflag, ComboPosition start_pos, bool allow_diagonal)
8389 {
8390 mapscr* scr = Map.ScrMakeValid(start_pos, CurrentLayer);
8391 if (!scr)
8392 return;
8393
8394 int num_combos_width = 16 * Map.getViewSize();
8395 int num_combos_height = 11 * Map.getViewSize();
8396
8397 auto combo_positions = flood_filler(start_pos, allow_diagonal, [&](ComboPosition pos){
8398 if (pos.x < 0 || pos.y < 0 || pos.x >= num_combos_width || pos.y >= num_combos_height)
8399 return false;
8400
8401 mapscr* scr = Map.Scr(pos, CurrentLayer);
8402 if (!scr || !scr->is_valid())
8403 return false;
8404
8405 if (scr->sflag[pos.truncate()] != targetflag)
8406 return false;
8407
8408 return true;
8409 });
8410
8411 for (auto& pos : combo_positions)
8412 Map.DoSetFlagCommand(pos, Flag);
8413 }
8414
8415 static void fill2(int32_t targetcombo, int32_t targetcset, ComboPosition pos, int32_t dir, int32_t diagonal, bool only_cset)
8416 {
8417 mapscr* scr = Map.Scr(pos, CurrentLayer);
8418 if (!scr || !scr->is_valid())
8419 return;
8420
8421 int cid = scr->data[pos.truncate()];
8422 int cset = scr->cset[pos.truncate()];
8423
8424 if (!only_cset)
8425 {
8426 if (cid == targetcombo)
8427 return;
8428 }
8429
8430 if (cset == targetcset)
8431 return;
8432
8433 cid = Combo;
8434 int8_t cs = CSet;
8435 if(draw_mode == dm_cpool)
8436 {
8437 combo_pool const& pool = combo_pools[combo_pool_pos];
8438 if(!pool.pick(cid,cs)) return;
8439 }
8440
8441 Map.DoSetComboCommand(pos, only_cset ? -1 : cid, cs);
8442
8443 int num_combos_width = 16 * Map.getViewSize();
8444 int num_combos_height = 11 * Map.getViewSize();
8445
8446 if (pos.y > 0 && dir != down)
8447 fill2(targetcombo, targetcset, pos + ComboPosition{0, -1}, up, diagonal, only_cset);
8448 if (pos.y < num_combos_height-1 && dir != up)
8449 fill2(targetcombo, targetcset, pos + ComboPosition{0, 1}, down, diagonal, only_cset);
8450 if (pos.x > 0 && dir != right)
8451 fill2(targetcombo, targetcset, pos + ComboPosition{-1, 0}, left, diagonal, only_cset);
8452 if (pos.x < num_combos_width-1 && dir != left)
8453 fill2(targetcombo, targetcset, pos + ComboPosition{1, 0}, right, diagonal, only_cset);
8454
8455 if (diagonal == 1)
8456 {
8457 if (pos.y > 0 && pos.x > 0 && dir != r_down)
8458 fill2(targetcombo, targetcset, pos + ComboPosition{-1, -1}, l_up, diagonal, only_cset);
8459 if (pos.y < num_combos_height-1 && pos.x < num_combos_width-1 && dir != l_up)
8460 fill2(targetcombo, targetcset, pos + ComboPosition{1, 1}, r_down, diagonal, only_cset);
8461 if (pos.x > 0 && pos.y < num_combos_height-1 && dir != r_up)
8462 fill2(targetcombo, targetcset, pos + ComboPosition{-1, 1}, l_down, diagonal, only_cset);
8463 if (pos.x < num_combos_width-1 && pos.y > 0 && dir != l_down)
8464 fill2(targetcombo, targetcset, pos + ComboPosition{1, -1}, r_up, diagonal, only_cset);
8465 }
8466 }
8467
8468
8469 enum SnapMode
8470 {
8471 SNAP_NONE, SNAP_HALF, SNAP_WHOLE
8472 };
8473 static void snap_xy(int& x, int& y, SnapMode mode, roundType rounding, optional<int> max_x = nullopt, optional<int> max_y = nullopt)
8474 {
8475 if(mode == SNAP_NONE)
8476 {
8477 if(max_x) x = vbound(x,*max_x,0);
8478 if(max_y) y = vbound(y,*max_y,0);
8479 return;
8480 }
8481 int xoff = 0, yoff = 0;
8482 switch(rounding)
8483 {
8484 case ROUND_TO_0:
8485 rounding = ROUND_DOWN;
8486 break;
8487 case ROUND_AWAY_0:
8488 rounding = ROUND_UP;
8489 break;
8490 }
8491 int r = 0;
8492 switch(mode)
8493 {
8494 case SNAP_HALF:
8495 r = 8;
8496 break;
8497 case SNAP_WHOLE:
8498 r = 16;
8499 break;
8500 }
8501 assert(r > 0);
8502 // r must be a power of 2, for bitwise reasons
8503 switch(rounding)
8504 {
8505 case ROUND_DOWN:
8506 break;
8507 case ROUND_UP:
8508 xoff = ((x & (r-1)) ? r : 0);
8509 yoff = ((y & (r-1)) ? r : 0);
8510 break;
8511 case ROUND_NEAREST:
8512 xoff = ((x & (r-1)) >= (r/2) ? r : 0);
8513 yoff = ((y & (r-1)) >= (r/2) ? r : 0);
8514 break;
8515 }
8516 x = (x & ~(r-1)) + xoff;
8517 y = (y & ~(r-1)) + yoff;
8518 if(max_x && x >= *max_x) x = *max_x-r;
8519 else if(max_x && x < 0) x = 0;
8520 if(max_y && y >= *max_y) y = *max_y-r;
8521 else if(max_y && y < 0) y = 0;
8522 }
8523
8524 static void doxypos(byte &px2, byte &py2, int32_t color, SnapMode snap_mode,
8525 SnapMode shift_mode, bool immediately, int32_t cursoroffx,
8526 int32_t cursoroffy, int32_t iconw, int32_t iconh)
8527 {
8528 int32_t tempcb=ComboBrush;
8529 ComboBrush=0;
8530 MouseSprite::set(ZQM_POINT_BOX);
8531
8532 int viz_off_x = (active_visible_screen ? active_visible_screen->dx * 256 : 0);
8533 int viz_off_y = (active_visible_screen ? active_visible_screen->dy * 176 : 0);
8534
8535 int32_t oldpx=px2, oldpy=py2;
8536 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
8537 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
8538 showxypos_x=px2 + viz_off_x;
8539 showxypos_y=py2 + viz_off_y;
8540 showxypos_w=iconw;
8541 showxypos_h=iconh;
8542 showxypos_color=vc(color);
8543 showxypos_icon=!showxypos_dummy;
8544 bool canedit=false;
8545 bool done=false;
8546
8547 clear_tooltip();
8548
8549 while(!done && (!(gui_mouse_b()&2) || immediately))
8550 {
8551 if(!gui_mouse_b() || immediately)
8552 {
8553 canedit=true;
8554 }
8555
8556 // TODO: would be nice if these bounds were based on the individual screen.
8557 if(canedit && gui_mouse_b()==1 && isinRect(gui_mouse_x(),gui_mouse_y(),startxint,startyint,(startxint+(256*mapscreen_screenunit_scale)-1),(startyint+(176*mapscreen_screenunit_scale)-1)))
8558 {
8559 set_mouse_range(startxint,startyint,int32_t(startxint+(256*mapscreen_screenunit_scale)-1),int32_t(startyint+(176*mapscreen_screenunit_scale)-1));
8560
8561 double offx = 0, offy = 0;
8562 roundType rounding = ROUND_DOWN;
8563 if(DragCenterOfSquares)
8564 {
8565 offx -= iconw*mapscreen_single_scale/2;
8566 offy -= iconh*mapscreen_single_scale/2;
8567 rounding = ROUND_NEAREST;
8568 }
8569 int32_t x, y;
8570 do
8571 {
8572 x=int32_t((gui_mouse_x()-startxint+offx)/mapscreen_single_scale)-cursoroffx;
8573 y=int32_t((gui_mouse_y()-startyint+offy)/mapscreen_single_scale)-cursoroffy;
8574 showxypos_cursor_icon=true;
8575 showxypos_cursor_color = showxypos_color;
8576 auto _mode = (key[KEY_LSHIFT] || key[KEY_RSHIFT]) ? shift_mode : snap_mode;
8577 showxypos_cursor_x = x-viz_off_x;
8578 showxypos_cursor_y = y-viz_off_y;
8579 snap_xy(showxypos_cursor_x, showxypos_cursor_y, _mode, rounding, 256, 176);
8580 showxypos_cursor_x += viz_off_x;
8581 showxypos_cursor_y += viz_off_y;
8582 custom_vsync();
8583 refresh(rALL | rNOCURSOR);
8584 int32_t xpos[2], ypos[2];
8585 int32_t x1,y1,x2,y2;
8586
8587 char b1[200] = {0};
8588 char b2[200] = {0};
8589 if(showxypos_dummy)
8590 strcpy(b1, "DUMMY MEASURING");
8591 else sprintf(b1, "%d %d",oldpx,oldpy);
8592 sprintf(b2, "%d %d (%d %d)",x-viz_off_x,y-viz_off_y,showxypos_cursor_x-viz_off_x,showxypos_cursor_y-viz_off_y);
8593
8594 int len[2] = {text_length(font,b1),text_length(font,b2)};
8595
8596 if(is_compact)
8597 {
8598 xpos[0] = 4;
8599 ypos[0] = layer_panel.y - 21;
8600 xpos[1] = xpos[0];
8601 ypos[1] = ypos[0]+10;
8602 }
8603 else
8604 {
8605 xpos[0] = 450;
8606 ypos[0] = 405;
8607 xpos[1] = xpos[0];
8608 ypos[1] = ypos[0]+10;
8609 }
8610
8611 x1 = xpos[0];
8612 y1 = ypos[0];
8613 x2 = xpos[0];
8614 y2 = ypos[0];
8615 for(auto q = 0; q < 2; ++q)
8616 {
8617 if(xpos[q] < x1)
8618 x1 = xpos[q];
8619 if(ypos[q] < y1)
8620 y1 = ypos[q];
8621 if(ypos[q] > y2)
8622 y2 = ypos[q];
8623 if(xpos[q] + len[q] > x2)
8624 x2 = xpos[q] + len[q];
8625 }
8626 x1 -= 4;
8627 y1 -= 2;
8628 y2 += text_height(font)+2;
8629
8630 auto minx = zc_min(xpos[0],xpos[1]);
8631 auto miny = zc_min(ypos[0],ypos[1]);
8632 rectfill(screen,x1,y1,x2,y2,vc(0));
8633 textprintf_ex(screen,font,xpos[0],ypos[0],vc(15),vc(0),"%s",b1);
8634 textprintf_ex(screen,font,xpos[1],ypos[1],vc(15),vc(0),"%s",b2);
8635 update_hw_screen();
8636 }
8637 while(gui_mouse_b()==1);
8638
8639 if(gui_mouse_b()==0)
8640 {
8641 auto _mode = (key[KEY_LSHIFT] || key[KEY_RSHIFT]) ? shift_mode : snap_mode;
8642 int x2 = vbound(x-viz_off_x,0,255);
8643 int y2 = vbound(y-viz_off_y,0,175);
8644 snap_xy(x2, y2, _mode, rounding, 256, 176);
8645 px2=byte(x2);
8646 py2=byte(y2);
8647 }
8648
8649 set_mouse_range(0,0,zq_screen_w-1,zq_screen_h-1);
8650 done=true;
8651 }
8652
8653 if(keypressed())
8654 {
8655 switch(readkey()>>8)
8656 {
8657 case KEY_ESC:
8658 case KEY_ENTER:
8659 goto finished;
8660 }
8661 }
8662
8663 custom_vsync();
8664 refresh(rALL | rNOCURSOR);
8665 }
8666
8667 finished:
8668 MouseSprite::set(ZQM_NORMAL);
8669 refresh(rMAP+rMENU);
8670
8671 while(gui_mouse_b())
8672 {
8673 /* do nothing */
8674 rest(1);
8675 }
8676
8677 showxypos_x=-1000;
8678 showxypos_y=-1000;
8679 showxypos_color=-1000;
8680 showxypos_ffc=-1000;
8681 showxypos_icon=false;
8682 showxypos_cursor_x=-1000;
8683 showxypos_cursor_y=-1000;
8684 showxypos_cursor_icon=false;
8685 showxypos_cursor_color=-1000;
8686 showxypos_dummy=false;
8687
8688 if(px2!=oldpx||py2!=oldpy)
8689 {
8690 saved=false;
8691 }
8692
8693 ComboBrush=tempcb;
8694 }
8695 static void doxypos(byte &px2,byte &py2,int32_t color,SnapMode snap_mode, optional<SnapMode> shift_mode = nullopt)
8696 {
8697 doxypos(px2,py2,color,snap_mode,shift_mode ? *shift_mode : snap_mode,false,0,0,16,16);
8698 }
8699
8700 bool placing_flags = false;
8701 void doflags()
8702 {
8703 placing_flags = true;
8704 int of=Flags;
8705 Flags=cFLAGS;
8706 refresh(rMAP | rNOCURSOR);
8707
8708 bool canedit=false;
8709 bool didShift = false;
8710 int tFlag = Flag;
8711 while(!(gui_mouse_b()&2) && !handle_close_btn_quit())
8712 {
8713 int x=gui_mouse_x();
8714 int y=gui_mouse_y();
8715 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
8716 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
8717 int startxint=mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
8718 int startyint=mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
8719 int cx=(x-startxint)/int(16*mapscreen_single_scale);
8720 int cy=(y-startyint)/int(16*mapscreen_single_scale);
8721 ComboPosition combo_pos = {cx, cy};
8722 int c = combo_pos.truncate();
8723
8724 if(!gui_mouse_b())
8725 canedit=true;
8726 bool shift = key[KEY_LSHIFT] || key[KEY_RSHIFT];
8727
8728 if(canedit && gui_mouse_b()==1 && isinRect(x,y,startxint,startyint,int(startx+(256*mapscreen_screenunit_scale)-1),int(starty+(176*mapscreen_screenunit_scale)-1)))
8729 {
8730 mapscr* cur_scr = Map.Scr(combo_pos, CurrentLayer);
8731 if (!cur_scr) continue;
8732
8733 Map.setCurrScr(Map.getScreenForPosition(combo_pos));
8734
8735 if(key[KEY_ALT]||key[KEY_ALTGR])
8736 Flag = cur_scr->sflag[c];
8737 else
8738 {
8739 saved=false;
8740 int tflag = Flag;
8741 if(shift)
8742 Flag = mfNONE;
8743 if(CurrentLayer!=0)
8744 {
8745 // Notify if they are using a flag that doesn't work on this layer.
8746 if(!skipLayerWarning && ((Flag >= mfTRAP_H && Flag < mfPUSHD) || (Flag == mfFAIRY) || (Flag == mfMAGICFAIRY)
8747 || (Flag == mfALLFAIRY) || (Flag == mfRAFT) || (Flag == mfRAFT_BRANCH)
8748 || (Flag == mfDIVE_ITEM) || (Flag == mfARMOS_SECRET) || (Flag == mfNOENEMY)
8749 || (Flag == mfZELDA)))
8750 {
8751 InfoDialog("Notice","You are currently working on layer "
8752 +to_string(CurrentLayer)
8753 +". This combo flag does not function on layers above '0'.").show();
8754 }
8755 if(!skipLayerWarning && CurrentLayer > 2 &&
8756 ((Flag == mfBLOCKHOLE) || (Flag >= mfPUSHD && Flag < mfNOBLOCKS)
8757 || (Flag == mfPUSHUD) || (Flag == mfPUSH4)))
8758 {
8759 InfoDialog("Notice","You are currently working on layer "
8760 +to_string(CurrentLayer)
8761 +". This combo flag does not function on layers above '2'.").show();
8762 }
8763 }
8764 if(CHECK_CTRL_CMD)
8765 {
8766 switch(fill_type)
8767 {
8768 case 0:
8769 flood_flag();
8770 break;
8771
8772 case 1:
8773 case 3:
8774 fill_4_flag();
8775 break;
8776
8777 case 2:
8778 case 4:
8779 fill_8_flag();
8780 break;
8781 }
8782 }
8783 else
8784 {
8785 Map.DoSetFlagCommand(combo_pos, Flag);
8786 }
8787 Flag = tflag;
8788 }
8789 }
8790
8791 if(mouse_z)
8792 {
8793 for(int i=0; i<abs(mouse_z); ++i)
8794 {
8795 if(mouse_z>0)
8796 onIncreaseFlag();
8797 else
8798 onDecreaseFlag();
8799 }
8800
8801 position_mouse_z(0);
8802 }
8803
8804 if(keypressed())
8805 {
8806 int k = readkey();
8807 switch(k>>8)
8808 {
8809 case KEY_ESC:
8810 case KEY_ENTER:
8811 goto finished;
8812 }
8813 object_message(dialogs+1, MSG_XCHAR, k);
8814 Flags=cFLAGS;
8815 }
8816
8817 MouseSprite::set(ZQM_FLAG_0+(shift?0:Flag%16));
8818
8819 refresh(rALL | rCLEAR | rNOCURSOR);
8820 custom_vsync();
8821 }
8822
8823 finished:
8824 Flags=of;
8825 placing_flags = false;
8826 MouseSprite::set(ZQM_NORMAL);
8827 refresh(rMAP+rMENU);
8828
8829 while(gui_mouse_b())
8830 {
8831 /* do nothing */
8832 rest(1);
8833 }
8834 }
8835
8836 // Drag FFCs around
8837 static void moveffc(int i, int cx, int cy)
8838 {
8839 mapscr* scr = active_visible_screen->scr;
8840 int screen = active_visible_screen->screen;
8841
8842 int32_t ffx = vbound(scr->ffcs[i].x.getFloor(),0,240);
8843 int32_t ffy = vbound(scr->ffcs[i].y.getFloor(),0,160);
8844 int32_t offx = ffx, offy = ffy;
8845 showxypos_ffc = i;
8846 doxypos((byte&)ffx,(byte&)ffy,15,SNAP_HALF,SNAP_NONE,true,0,0,(scr->ffTileWidth(i)*16),(scr->ffTileHeight(i)*16));
8847 if(ffx > 240) ffx = 240;
8848 if(ffy > 160) ffy = 160;
8849 if((ffx != offx) || (ffy != offy))
8850 {
8851 auto set_ffc_data = set_ffc_command::create_data(scr->ffcs[i]);
8852 set_ffc_data.x = ffx;
8853 set_ffc_data.y = ffy;
8854 Map.DoSetFFCCommand(Map.getCurrMap(), screen, i, set_ffc_data);
8855 saved = false;
8856 }
8857 }
8858
8859 void set_brush_width(int32_t width);
8860 void set_brush_height(int32_t height);
8861
8862 int32_t set_brush_width_1()
8863 {
8864 set_brush_width(1);
8865 return D_O_K;
8866 }
8867 int32_t set_brush_width_2()
8868 {
8869 set_brush_width(2);
8870 return D_O_K;
8871 }
8872 int32_t set_brush_width_3()
8873 {
8874 set_brush_width(3);
8875 return D_O_K;
8876 }
8877 int32_t set_brush_width_4()
8878 {
8879 set_brush_width(4);
8880 return D_O_K;
8881 }
8882 int32_t set_brush_width_5()
8883 {
8884 set_brush_width(5);
8885 return D_O_K;
8886 }
8887 int32_t set_brush_width_6()
8888 {
8889 set_brush_width(6);
8890 return D_O_K;
8891 }
8892 int32_t set_brush_width_7()
8893 {
8894 set_brush_width(7);
8895 return D_O_K;
8896 }
8897 int32_t set_brush_width_8()
8898 {
8899 set_brush_width(8);
8900 return D_O_K;
8901 }
8902 int32_t set_brush_width_9()
8903 {
8904 set_brush_width(9);
8905 return D_O_K;
8906 }
8907 int32_t set_brush_width_10()
8908 {
8909 set_brush_width(10);
8910 return D_O_K;
8911 }
8912 int32_t set_brush_width_11()
8913 {
8914 set_brush_width(11);
8915 return D_O_K;
8916 }
8917 int32_t set_brush_width_12()
8918 {
8919 set_brush_width(12);
8920 return D_O_K;
8921 }
8922 int32_t set_brush_width_13()
8923 {
8924 set_brush_width(13);
8925 return D_O_K;
8926 }
8927 int32_t set_brush_width_14()
8928 {
8929 set_brush_width(14);
8930 return D_O_K;
8931 }
8932 int32_t set_brush_width_15()
8933 {
8934 set_brush_width(15);
8935 return D_O_K;
8936 }
8937 int32_t set_brush_width_16()
8938 {
8939 set_brush_width(16);
8940 return D_O_K;
8941 }
8942
8943 int32_t set_brush_height_1()
8944 {
8945 set_brush_height(1);
8946 return D_O_K;
8947 }
8948 int32_t set_brush_height_2()
8949 {
8950 set_brush_height(2);
8951 return D_O_K;
8952 }
8953 int32_t set_brush_height_3()
8954 {
8955 set_brush_height(3);
8956 return D_O_K;
8957 }
8958 int32_t set_brush_height_4()
8959 {
8960 set_brush_height(4);
8961 return D_O_K;
8962 }
8963 int32_t set_brush_height_5()
8964 {
8965 set_brush_height(5);
8966 return D_O_K;
8967 }
8968 int32_t set_brush_height_6()
8969 {
8970 set_brush_height(6);
8971 return D_O_K;
8972 }
8973 int32_t set_brush_height_7()
8974 {
8975 set_brush_height(7);
8976 return D_O_K;
8977 }
8978 int32_t set_brush_height_8()
8979 {
8980 set_brush_height(8);
8981 return D_O_K;
8982 }
8983 int32_t set_brush_height_9()
8984 {
8985 set_brush_height(9);
8986 return D_O_K;
8987 }
8988 int32_t set_brush_height_10()
8989 {
8990 set_brush_height(10);
8991 return D_O_K;
8992 }
8993 int32_t set_brush_height_11()
8994 {
8995 set_brush_height(11);
8996 return D_O_K;
8997 }
8998
8999
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_width_menu
9000 204 {
9001
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1", set_brush_width_1 },
9002
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2", set_brush_width_2 },
9003
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3", set_brush_width_3 },
9004
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4", set_brush_width_4 },
9005
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "5", set_brush_width_5 },
9006
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "6", set_brush_width_6 },
9007
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "7", set_brush_width_7 },
9008
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "8", set_brush_width_8 },
9009
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "9", set_brush_width_9 },
9010
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "10", set_brush_width_10 },
9011
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "11", set_brush_width_11 },
9012
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "12", set_brush_width_12 },
9013
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "13", set_brush_width_13 },
9014
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "14", set_brush_width_14 },
9015
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "15", set_brush_width_15 },
9016
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "16", set_brush_width_16 },
9017 };
9018
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_height_menu
9019 144 {
9020
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1", set_brush_height_1 },
9021
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2", set_brush_height_2 },
9022
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3", set_brush_height_3 },
9023
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4", set_brush_height_4 },
9024
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "5", set_brush_height_5 },
9025
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "6", set_brush_height_6 },
9026
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "7", set_brush_height_7 },
9027
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "8", set_brush_height_8 },
9028
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "9", set_brush_height_9 },
9029
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "10", set_brush_height_10 },
9030
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "11", set_brush_height_11 },
9031 };
9032
9033 int toggle_autobrush();
9034 int toggle_combobrush();
9035 int toggle_floatbrush();
9036 enum
9037 {
9038 MENUID_BRUSH_AUTOBRUSH,
9039 MENUID_BRUSH_WIDTH,
9040 MENUID_BRUSH_HEIGHT,
9041 MENUID_BRUSH_COMBOBRUSH,
9042 MENUID_BRUSH_FLOATBRUSH,
9043 };
9044
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_menu
9045 72 {
9046
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "AutoBrush", toggle_autobrush, MENUID_BRUSH_AUTOBRUSH },
9047
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Brush Width ", &brush_width_menu, MENUID_BRUSH_WIDTH },
9048
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Brush Height ", &brush_height_menu, MENUID_BRUSH_HEIGHT },
9049
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "ComboBrush", toggle_combobrush, MENUID_BRUSH_COMBOBRUSH },
9050
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "FloatBrush", toggle_floatbrush, MENUID_BRUSH_FLOATBRUSH },
9051 };
9052 int toggle_autobrush()
9053 {
9054 AutoBrush = AutoBrush ? 0 : 1;
9055 BrushWidth = BrushHeight = 1;
9056 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
9057 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
9058 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
9059 zc_set_config("zquest","autobrush",AutoBrush);
9060 return D_O_K;
9061 }
9062 int toggle_combobrush()
9063 {
9064 ComboBrush = ComboBrush ? 0 : 1;
9065 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
9066 zc_set_config("zquest","combo_brush",ComboBrush);
9067 return D_O_K;
9068 }
9069 int toggle_floatbrush()
9070 {
9071 FloatBrush = FloatBrush ? 0 : 1;
9072 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
9073 zc_set_config("zquest","float_brush",FloatBrush);
9074 return D_O_K;
9075 }
9076
9077 int32_t set_flood();
9078 int32_t set_fill_4();
9079 int32_t set_fill_8();
9080 int32_t set_fill2_4();
9081 int32_t set_fill2_8();
9082
9083 // Sets every combo.
9084 void flood()
9085 {
9086 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9087 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9088 if (!scr || !scr->is_valid())
9089 return;
9090
9091 saved=false;
9092
9093 bool include_combos = !(key[KEY_LSHIFT]||key[KEY_RSHIFT]);
9094
9095 int num_combos_width = 16 * Map.getViewSize();
9096 int num_combos_height = 11 * Map.getViewSize();
9097
9098 Map.StartListCommand();
9099 for (int x = 0; x < num_combos_width; x++)
9100 {
9101 for (int y = 0; y < num_combos_height; y++)
9102 {
9103 ComboPosition pos = {x, y};
9104 mapscr* scr = Map.Scr(pos, CurrentLayer);
9105 if (!scr || !scr->is_valid())
9106 continue;
9107
9108 if (draw_mode == dm_auto)
9109 draw_autocombo(pos, gui_mouse_b() & 2);
9110 else
9111 Map.DoSetComboCommand(pos, include_combos ? Combo : -1, CSet);
9112 }
9113 }
9114 Map.FinishListCommand();
9115
9116 refresh(rMAP+rSCRMAP);
9117 }
9118 void flood_flag()
9119 {
9120 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9121 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9122 if (!scr || !scr->is_valid())
9123 return;
9124
9125 saved=false;
9126
9127 int num_combos_width = 16 * Map.getViewSize();
9128 int num_combos_height = 11 * Map.getViewSize();
9129
9130 Map.StartListCommand();
9131 for (int x = 0; x < num_combos_width; x++)
9132 {
9133 for (int y = 0; y < num_combos_height; y++)
9134 {
9135 ComboPosition pos = {x, y};
9136 mapscr* scr = Map.Scr(pos, CurrentLayer);
9137 if (!scr || !scr->is_valid())
9138 continue;
9139
9140 Map.DoSetFlagCommand(pos, Flag);
9141 }
9142 }
9143 Map.FinishListCommand();
9144
9145 refresh(rMAP+rSCRMAP);
9146 }
9147
9148 void fill_4()
9149 {
9150 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9151 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9152 if (!scr)
9153 return;
9154
9155 int c = pos.truncate();
9156 if (draw_mode == dm_cpool || draw_mode == dm_auto
9157 || (scr->cset[c]!=CSet || (scr->data[c]!=Combo && !(key[KEY_LSHIFT]||key[KEY_RSHIFT]))))
9158 {
9159 saved=false;
9160
9161 Map.StartListCommand();
9162 if (draw_mode == dm_auto && (combo_autos[combo_auto_pos].getType() == AUTOCOMBO_FENCE ||
9163 combo_autos[combo_auto_pos].getType() == AUTOCOMBO_Z4))
9164 {
9165 draw_autocombo_command(pos);
9166 }
9167 else
9168 {
9169 bool allow_diagonal = false;
9170 fill(scr->data[c], scr->cset[c], pos, allow_diagonal, (key[KEY_LSHIFT] || key[KEY_RSHIFT]));
9171 }
9172 Map.FinishListCommand();
9173 refresh(rMAP+rSCRMAP);
9174 }
9175 }
9176 void fill_4_flag()
9177 {
9178 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9179 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9180 if (!scr)
9181 return;
9182
9183 int flag = scr->sflag[pos.truncate()];
9184 if (flag != Flag)
9185 {
9186 saved=false;
9187
9188 Map.StartListCommand();
9189 bool allow_diagonal = false;
9190 fill_flag(flag, pos, allow_diagonal);
9191 Map.FinishListCommand();
9192 refresh(rMAP+rSCRMAP);
9193 }
9194 }
9195 void fill_8()
9196 {
9197 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9198 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9199 if (!scr)
9200 return;
9201
9202 int c = pos.truncate();
9203 if (draw_mode == dm_cpool || draw_mode == dm_auto
9204 || (scr->cset[c] != CSet ||
9205 (scr->data[c] != Combo &&
9206 !(key[KEY_LSHIFT]||key[KEY_RSHIFT]))))
9207 {
9208 saved=false;
9209
9210 Map.StartListCommand();
9211 bool allow_diagonal = true;
9212 fill(scr->data[c], scr->cset[c], pos, allow_diagonal, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9213 Map.FinishListCommand();
9214
9215 refresh(rMAP+rSCRMAP);
9216 }
9217 }
9218 void fill_8_flag()
9219 {
9220 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9221 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9222 if (!scr)
9223 return;
9224
9225 int flag = scr->sflag[pos.truncate()];
9226 if (flag != Flag)
9227 {
9228 saved=false;
9229
9230 Map.StartListCommand();
9231 bool allow_diagonal = true;
9232 fill_flag(flag, pos, allow_diagonal);
9233 Map.FinishListCommand();
9234 refresh(rMAP+rSCRMAP);
9235 }
9236 }
9237
9238 void fill2_4()
9239 {
9240 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9241 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9242 if (!scr)
9243 return;
9244
9245 saved=false;
9246
9247 Map.StartListCommand();
9248 fill2(Combo, CSet, pos, 255, 0, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9249 Map.FinishListCommand();
9250 refresh(rMAP+rSCRMAP);
9251 }
9252
9253 void fill2_8()
9254 {
9255 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9256 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9257 if (!scr)
9258 return;
9259
9260 saved=false;
9261
9262 Map.StartListCommand();
9263 fill2(Combo, CSet, pos, 255, 1, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9264 Map.FinishListCommand();
9265
9266 refresh(rMAP+rSCRMAP);
9267 }
9268
9269
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu fill_menu
9270 72 {
9271
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Flood", set_flood, 0 },
9272
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill (4-way)", set_fill_4, 1 },
9273
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill (8-way)", set_fill_8, 2 },
9274
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill2 (4-way)", set_fill2_4, 3 },
9275
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill2 (8-way)", set_fill2_8, 4 },
9276 };
9277 void set_filltype(int ty)
9278 {
9279 fill_type = ty;
9280 fill_menu.select_only_uid(ty);
9281 }
9282
9283 int32_t set_flood()
9284 {
9285 set_filltype(0);
9286 return D_O_K;
9287 }
9288
9289 int32_t set_fill_4()
9290 {
9291 set_filltype(1);
9292 return D_O_K;
9293 }
9294
9295 int32_t set_fill_8()
9296 {
9297 set_filltype(2);
9298 return D_O_K;
9299 }
9300
9301 int32_t set_fill2_4()
9302 {
9303 set_filltype(3);
9304 return D_O_K;
9305 }
9306
9307 int32_t set_fill2_8()
9308 {
9309 set_filltype(4);
9310 return D_O_K;
9311 }
9312
9313 int32_t draw_block_1_2()
9314 {
9315 draw_block(mouse_combo_pos,1,2);
9316 return D_O_K;
9317 }
9318
9319 int32_t draw_block_2_1()
9320 {
9321 draw_block(mouse_combo_pos,2,1);
9322 return D_O_K;
9323 }
9324
9325 int32_t draw_block_2_2()
9326 {
9327 draw_block(mouse_combo_pos,2,2);
9328 return D_O_K;
9329 }
9330
9331 int32_t draw_block_2_3()
9332 {
9333 draw_block(mouse_combo_pos,2,3);
9334 return D_O_K;
9335 }
9336
9337 int32_t draw_block_3_2()
9338 {
9339 draw_block(mouse_combo_pos,3,2);
9340 return D_O_K;
9341 }
9342
9343 int32_t draw_block_3_3()
9344 {
9345 draw_block(mouse_combo_pos,3,3);
9346 return D_O_K;
9347 }
9348
9349 int32_t draw_block_4_2()
9350 {
9351 draw_block(mouse_combo_pos,4,2);
9352 return D_O_K;
9353 }
9354
9355 int32_t draw_block_4_4()
9356 {
9357 draw_block(mouse_combo_pos,4,4);
9358 return D_O_K;
9359 }
9360
9361
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu draw_block_menu
9362 108 {
9363
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1x2", draw_block_1_2 },
9364
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x1", draw_block_2_1 },
9365
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x2", draw_block_2_2 },
9366
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x3", draw_block_2_3 },
9367
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3x2", draw_block_3_2 },
9368
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3x3", draw_block_3_3 },
9369
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4x2", draw_block_4_2 },
9370
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4x4", draw_block_4_4 },
9371 };
9372
9373
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_screen_menu
9374 60 {
9375
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste", onPaste },
9376
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste All", onPasteAll },
9377
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste to All", onPasteToAll },
9378
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste All to All", onPasteAllToAll },
9379 };
9380
9381 int32_t scrollto_cmb(int32_t cid)
9382 {
9383 auto& sqr = combolist[current_combolist];
9384 int32_t res = vbound(cid-(sqr.w*sqr.h/2),0,MAXCOMBOS-(sqr.w*sqr.h));
9385 res -= res%sqr.w;
9386 return res;
9387 }
9388 int32_t scrollto_alias(int32_t alid)
9389 {
9390 auto& sqr = comboaliaslist[current_comboalist];
9391 int32_t res = vbound(alid-(sqr.w*sqr.h/2),0,MAXCOMBOALIASES-(sqr.w*sqr.h));
9392 res -= res%sqr.w;
9393 return res;
9394 }
9395
9396 int32_t scrollto_cpool(int32_t cpid)
9397 {
9398 auto& sqr = comboaliaslist[current_cpoollist];
9399 int32_t res = vbound(cpid-(sqr.w*sqr.h/2),0,MAXCOMBOPOOLS-(sqr.w*sqr.h));
9400 res -= res%sqr.w;
9401 return res;
9402 }
9403
9404 int32_t scrollto_cauto(int32_t caid)
9405 {
9406 auto& sqr = comboaliaslist[current_cautolist];
9407 int32_t res = vbound(caid - (sqr.w * sqr.h / 2), 0, MAXCOMBOPOOLS - (sqr.w * sqr.h));
9408 res -= res % sqr.w;
9409 return res;
9410 }
9411
9412 void add_favorite_combo_block(int32_t favind, int32_t cid, bool force)
9413 {
9414 int32_t w = vbound(BrushWidth, 1, 4);
9415 int32_t h = vbound(BrushHeight, 1, 7);
9416 for (int32_t xi = 0; xi < w; ++xi)
9417 {
9418 for (int32_t yi = 0; yi < h; ++yi)
9419 {
9420 int32_t cx = cid % 4;
9421 int32_t cy = cid / 4;
9422 int32_t cc = (cy + yi) * 4 + cx + xi;
9423 int32_t fx = favind % FAVORITECOMBO_PER_ROW;
9424 int32_t fy = favind / FAVORITECOMBO_PER_ROW;
9425 int32_t fc = (fy + yi) * FAVORITECOMBO_PER_ROW + fx + xi + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
9426
9427 if (cx + xi < 4 && cc < MAXCOMBOS && fx + xi < FAVORITECOMBO_PER_ROW && fy + yi < FAVORITECOMBO_PER_COLUMN)
9428 {
9429 if (favorite_combos[fc] < 0 || force)
9430 {
9431 favorite_combo_modes[fc] = dm_normal;
9432 favorite_combos[fc] = cc;
9433 }
9434 }
9435 }
9436 }
9437 }
9438
9439 void onRCSelectCombo(int32_t c)
9440 {
9441 int32_t drawmap, drawscr;
9442
9443 if(CurrentLayer==0)
9444 {
9445 drawmap=Map.getCurrMap();
9446 drawscr=Map.getCurrScr();
9447 }
9448 else
9449 {
9450 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
9451 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
9452 }
9453 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
9454 if(!draw_mapscr) return;
9455
9456 Combo=draw_mapscr->data[c];
9457 if(AutoBrush)
9458 BrushWidth = BrushHeight = 1;
9459 }
9460
9461 void onRCScrollToombo(int32_t c)
9462 {
9463 int32_t drawmap, drawscr;
9464
9465 if(CurrentLayer==0)
9466 {
9467 drawmap=Map.getCurrMap();
9468 drawscr=Map.getCurrScr();
9469 }
9470 else
9471 {
9472 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
9473 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
9474 }
9475 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
9476 if(!draw_mapscr) return;
9477
9478 auto& sqr = combolist[current_combolist];
9479 First[current_combolist]=scrollto_cmb(draw_mapscr->data[c]);
9480 }
9481
9482 enum
9483 {
9484 MENUID_RCSCREEN_PASTE,
9485 MENUID_RCSCREEN_ADVPASTE,
9486 MENUID_RCSCREEN_SPECPASTE,
9487 };
9488
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu rc_menu_screen
9489 60 {
9490
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Copy Screen", onCopy },
9491
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste Screen", &paste_screen_menu, MENUID_RCSCREEN_PASTE },
9492
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "...Advanced Paste", &paste_menu, MENUID_RCSCREEN_ADVPASTE },
9493
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "...Special Paste", &paste_item_menu, MENUID_RCSCREEN_SPECPASTE },
9494 };
9495
9496 void call_options_dlg();
9497 int32_t onOptions()
9498 {
9499 call_options_dlg();
9500 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
9501 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
9502 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
9503 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
9504 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
9505 return D_O_K;
9506 }
9507
9508 void follow_twarp(int warpindex)
9509 {
9510 if(warpindex >= 4)
9511 {
9512 InfoDialog("Random Tile Warp",
9513 "This is a random tile warp combo, so it chooses"
9514 " randomly between the screen's four Tile Warps.").show();
9515 warpindex=zc_oldrand()&3;
9516 }
9517
9518 int32_t tm = Map.getCurrMap();
9519 int32_t ts = Map.getCurrScr();
9520 int32_t wt = Map.CurrScr()->tilewarptype[warpindex];
9521
9522 if(wt==wtCAVE || wt==wtNOWARP)
9523 {
9524 char buf[56];
9525 InfoDialog(warptype_string[wt],fmt::format("This screen's Tile Warp {} is set to {}, so it doesn't lead to another screen.",'A'+warpindex,warptype_string[wt]));
9526 return;
9527 }
9528
9529 Map.dowarp(0,warpindex);
9530
9531 if(ts!=Map.getCurrScr() || tm!=Map.getCurrMap())
9532 {
9533 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(warpindex*2))&3;
9534 FlashWarpClk = 32;
9535 }
9536 }
9537 void edit_twarp(int warpindex)
9538 {
9539 if(warpindex>=4)
9540 {
9541 InfoDialog("Random Tile Warp",
9542 "This is a random tile warp combo, so it chooses"
9543 " randomly between the screen's four Tile Warps.").show();
9544 warpindex=zc_oldrand()&3;
9545 }
9546
9547 if(warpindex > -1 && warpindex < 4)
9548 onTileWarpIndex(warpindex);
9549 }
9550
9551 int toggle_linked_scrolling()
9552 {
9553 LinkedScroll = LinkedScroll ? 0 : 1;
9554 zc_set_config("zquest","linked_comboscroll",LinkedScroll);
9555 return D_O_K;
9556 }
9557 void on_scroll_cpane()
9558 {
9559 switch (draw_mode)
9560 {
9561 case dm_alias:
9562 combo_alistpos[current_comboalist] = scrollto_alias(combo_apos);
9563 break;
9564 case dm_cpool:
9565 combo_pool_listpos[current_cpoollist] = scrollto_cpool(combo_pool_pos);
9566 break;
9567 case dm_auto:
9568 combo_auto_listpos[current_cautolist] = scrollto_cauto(combo_auto_pos);
9569 break;
9570 default:
9571 First[current_combolist] = scrollto_cmb(Combo);
9572 break;
9573 }
9574 }
9575 void on_edit_cpane()
9576 {
9577 switch (draw_mode)
9578 {
9579 case dm_alias:
9580 onEditComboAlias();
9581 break;
9582 case dm_cpool:
9583 onEditComboPool();
9584 break;
9585 case dm_auto:
9586 onEditAutoCombo();
9587 break;
9588 default:
9589 reset_combo_animations();
9590 reset_combo_animations2();
9591 edit_combo(Combo, true, CSet);
9592 setup_combo_animations();
9593 setup_combo_animations2();
9594 break;
9595 }
9596 }
9597 void on_cpane_page()
9598 {
9599 switch(draw_mode)
9600 {
9601 case dm_normal:
9602 combo_screen(Combo>>8,Combo);
9603 break;
9604 case dm_alias:
9605 call_alias_pages(combo_apos);
9606 break;
9607 case dm_auto:
9608 call_autoc_pages(combo_auto_pos);
9609 break;
9610 case dm_cpool:
9611 call_cpool_pages(combo_pool_pos);
9612 break;
9613 }
9614 }
9615 void open_cpane_tilepage()
9616 {
9617 onGotoTiles(combobuf[Combo].o_tile);
9618 }
9619 static int _clicked_fav = 0;
9620 void fav_rc_remove()
9621 {
9622 favorite_combo_modes[_clicked_fav] = dm_normal;
9623 favorite_combos[_clicked_fav] = -1;
9624 saved = false;
9625 }
9626 void popup_favorites_rc(int f, int x, int y)
9627 {
9628 _clicked_fav = f;
9629 string type;
9630 switch (draw_mode)
9631 {
9632 case dm_alias:
9633 type = "Alias";
9634 break;
9635 case dm_cpool:
9636 type = "Pool";
9637 break;
9638 case dm_auto:
9639 type = "Autocombo";
9640 break;
9641 case dm_normal:
9642 type = "Combo";
9643 break;
9644 default: return;
9645 }
9646 NewMenu rcmenu
9647 {
9648 { fmt::format("Scroll to {}", type), on_scroll_cpane },
9649 { fmt::format("Edit {}", type), on_edit_cpane },
9650 { fmt::format("Open {} Page", type), on_cpane_page },
9651 { fmt::format("Remove Fav {}", type), fav_rc_remove },
9652 };
9653 switch (draw_mode)
9654 {
9655 case dm_normal:
9656 rcmenu.add({
9657 {},
9658 { "Open Tile Page", open_cpane_tilepage },
9659 });
9660 break;
9661 }
9662 rcmenu.pop(x, y);
9663 }
9664 void popup_cpane_rc(int x, int y)
9665 {
9666 string type;
9667 switch (draw_mode)
9668 {
9669 case dm_alias:
9670 type = "Alias";
9671 break;
9672 case dm_cpool:
9673 type = "Pool";
9674 break;
9675 case dm_auto:
9676 type = "Autocombo";
9677 break;
9678 case dm_normal:
9679 type = "Combo";
9680 break;
9681 default: return;
9682 }
9683 NewMenu rcmenu;
9684 switch(draw_mode)
9685 {
9686 case dm_normal:
9687 rcmenu.add({
9688 { fmt::format("Edit {}", type), on_edit_cpane },
9689 { fmt::format("Open {} Page", type), on_cpane_page },
9690 { "Open Tile Page", open_cpane_tilepage },
9691 { "Combo Locations", onComboLocationReport },
9692 {},
9693 { "Scroll to Page...", onGotoPage },
9694 { "Linked Scrolling", toggle_linked_scrolling, nullopt, LinkedScroll ? MFL_SEL : 0 },
9695 });
9696 break;
9697 case dm_alias:
9698 case dm_cpool:
9699 case dm_auto:
9700 rcmenu.add({
9701 { fmt::format("Edit {}", type), on_edit_cpane },
9702 { fmt::format("Open {} Page", type), on_cpane_page },
9703 {},
9704 { "Scroll to Page...", onGotoPage },
9705 { "Linked Scrolling", toggle_linked_scrolling, nullopt, LinkedScroll ? MFL_SEL : 0 },
9706 });
9707 break;
9708 }
9709 rcmenu.pop(x, y);
9710 }
9711
9712 void set_brush_width(int32_t width)
9713 {
9714 BrushWidth = width;
9715 for(int q = 0; q < brush_width_menu.size(); ++q)
9716 brush_width_menu.at(q)->select(q==BrushWidth-1);
9717 refresh(rALL);
9718 }
9719
9720 void set_brush_height(int32_t height)
9721 {
9722 BrushHeight = height;
9723 for(int q = 0; q < brush_height_menu.size(); ++q)
9724 brush_height_menu.at(q)->select(q==BrushHeight-1);
9725 refresh(rALL);
9726 }
9727
9728 1 void restore_mouse()
9729 {
9730 1 ComboBrushPause=1;
9731 1 MouseSprite::set(ZQM_NORMAL);
9732 1 }
9733
9734 static int32_t comboa_cnt=0;
9735 static int32_t combop_cnt=0;
9736 static int32_t layer_cnt=0;
9737
9738 static char paste_ffc_menu_text[21];
9739 static char paste_ffc_menu_text2[21];
9740 static char follow_warp_menu_text[21];
9741 static char follow_warp_menu_text2[21];
9742
9743 static int fake_mouse_b(){return 0;}
9744 static int (*mouseb_proc)();
9745 static bool killed_mouse = false;
9746 void zq_killmouse()
9747 {
9748 if(killed_mouse) return;
9749 mouseb_proc = gui_mouse_b;
9750 gui_mouse_b = fake_mouse_b;
9751 killed_mouse = true;
9752 }
9753 void zq_restoremouse()
9754 {
9755 if(!killed_mouse) return;
9756 gui_mouse_b = mouseb_proc;
9757 killed_mouse = false;
9758 }
9759
9760
9761 void domouse()
9762 {
9763 static int mouse_down = 0;
9764 static int32_t scrolldelay = 0;
9765 auto mousexy = zc_get_mouse();
9766 auto x = mousexy.first;
9767 auto y = mousexy.second;
9768 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
9769 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
9770 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
9771 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
9772 int32_t cx=(x-startx)/(16*mapscreen_single_scale);
9773 int32_t cy=(y-starty)/(16*mapscreen_single_scale);
9774 ComboPosition combo_pos = {cx, cy};
9775
9776 if (draw_mode == dm_auto)
9777 {
9778 if (combo_pos != mouse_combo_pos)
9779 combobrushoverride = get_autocombo_floating_cid(combo_pos, false);
9780 }
9781 else
9782 combobrushoverride = -1;
9783
9784 mouse_combo_pos = combo_pos;
9785 update_combobrush();
9786
9787 ++scrolldelay;
9788
9789 bool x_on_list = false;
9790 for(auto q = 0; q < num_combo_cols; ++q)
9791 {
9792 if((x>=combolist[q].x) && (x<combolist[q].x+(combolist[q].xscale*combolist[q].w)))
9793 {
9794 x_on_list = true;
9795 break;
9796 }
9797 }
9798 if(MouseScroll && x_on_list && (key[KEY_LSHIFT] || key[KEY_RSHIFT] || (scrolldelay&3)==0))
9799 {
9800 int32_t test_list=0;
9801
9802 for(test_list=0; test_list<num_combo_cols; ++test_list)
9803 {
9804 if((x>=combolist[test_list].x) && (x<combolist[test_list].x+(combolist[test_list].xscale*combolist[test_list].w)))
9805 {
9806 break;
9807 }
9808 }
9809
9810 if(test_list<num_combo_cols)
9811 {
9812 if(y>=combolist[test_list].y-mouse_scroll_h && y<=combolist[test_list].y && First[test_list])
9813 {
9814 if((CHECK_CTRL_CMD)&&(key[KEY_ALT] || key[KEY_ALTGR]))
9815 {
9816 First[test_list]=0;
9817 }
9818 else if(CHECK_CTRL_CMD)
9819 {
9820 First[test_list]-=zc_min(First[test_list],256);
9821 }
9822 else if(key[KEY_ALT] || key[KEY_ALTGR])
9823 {
9824 First[test_list]-=zc_min(First[test_list],(combolist[test_list].w*combolist[test_list].h));
9825 }
9826 else
9827 {
9828 First[test_list]-=zc_min(First[test_list],combolist[test_list].w);
9829 }
9830 }
9831
9832 if(y>=combolist[test_list].y+(combolist[test_list].h*combolist[test_list].yscale)-1 && y<combolist[test_list].y+(combolist[test_list].h*combolist[test_list].yscale)+mouse_scroll_h-1 && First[test_list]<(MAXCOMBOS-(combolist[test_list].w*combolist[test_list].h)))
9833 {
9834 int32_t offset = combolist[test_list].w*combolist[test_list].h;
9835
9836 if((CHECK_CTRL_CMD)&&(key[KEY_ALT] || key[KEY_ALTGR]))
9837 {
9838 First[test_list]=MAXCOMBOS-offset;
9839 }
9840 else if(CHECK_CTRL_CMD)
9841 {
9842 First[test_list] = zc_min(MAXCOMBOS-offset, First[test_list]+256);
9843 }
9844 else if(key[KEY_ALT] || key[KEY_ALTGR])
9845 {
9846 First[test_list] = zc_min(MAXCOMBOS-offset, First[test_list]+ offset);
9847 }
9848 else
9849 {
9850 First[test_list] = zc_min(MAXCOMBOS - offset, First[test_list] + combolist[test_list].w);
9851 }
9852 }
9853 }
9854 }
9855
9856 // The screen for this combo_pos, layer 0. Used to access ffcs.
9857 mapscr* scr = Map.Scr(combo_pos);
9858 // The screen for this combo_pos at the CurrentLayer. Could be same as scr.
9859 mapscr* draw_mapscr = scr && CurrentLayer ? Map.Scr(combo_pos, CurrentLayer) : scr;
9860 int c = combo_pos.truncate();
9861 set_active_visible_screen(scr);
9862
9863 //-------------
9864 //tooltip stuff
9865 //-------------
9866 if (active_visible_screen && isinRect(x,y,startxint,startyint,startxint+(256*mapscreen_screenunit_scale)-1,startyint+(176*mapscreen_screenunit_scale)-1))
9867 {
9868 static int mapscr_tooltip_id = ttip_register_id();
9869 bool did_ffttip = false;
9870 int num_ffcs = scr->numFFC();
9871 for(int32_t i=num_ffcs-1; i>=0; i--)
9872 if(scr->ffcs[i].data !=0 && (scr->ffcs[i].layer >= CurrentLayer || (scr->ffcs[i].flags&ffc_overlay)))
9873 {
9874 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
9875 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
9876 int32_t ffw = scr->ffTileWidth(i)*16;
9877 int32_t ffh = scr->ffTileHeight(i)*16;
9878 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
9879 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
9880
9881 if(cx2 >= ffx && cx2 < ffx+ffw && cy2 >= ffy && cy2 < ffy+ffh)
9882 {
9883 // FFC tooltip
9884 if(tooltip_current_ffc != i)
9885 {
9886 clear_tooltip();
9887 }
9888
9889 tooltip_current_ffc = i;
9890 char msg[1024] = {0};
9891 auto& ff = scr->ffcs[i];
9892 sprintf(msg,"FFC: %d Combo: %d\nCSet: %d Type: %s\nScript: %s",
9893 i+1, ff.data,ff.data,
9894 combo_class_buf[combobuf[ff.data].type].name,
9895 (ff.script<=0 ? "(None)" : ffcmap[ff.script-1].scriptname.substr(0,400).c_str()));
9896 ttip_install(mapscr_tooltip_id, msg, startxint+(ffx*mapscreen_single_scale), startyint+(ffy*mapscreen_single_scale), ffw*mapscreen_single_scale, ffh*mapscreen_single_scale, x, y);
9897 did_ffttip = true;
9898 break;
9899 }
9900 }
9901 if(!did_ffttip)
9902 {
9903 if(unsigned(c) < 176 && draw_mapscr && !gui_mouse_b())
9904 {
9905 int cid = draw_mapscr->data[c];
9906 newcombo const& cmb = combobuf[cid];
9907 std::ostringstream oss;
9908 int cs = draw_mapscr->cset[c];
9909 int sflag = draw_mapscr->sflag[c];
9910 oss << "Pos: " << c
9911 << "\nCombo: " << cid
9912 << "\nCSet: " << cs;
9913 if(sflag || cmb.flag)
9914 oss << "\nFlags: " << sflag << ", " << (int)cmb.flag;
9915 if(cmb.type)
9916 oss << "\nCombo type: " << combo_class_buf[cmb.type].name;
9917 if(cmb.label[0])
9918 oss << "\nLabel: " << cmb.label;
9919 ttip_install(mapscr_tooltip_id, oss.str().c_str(), startxint+(cx*16*mapscreen_single_scale), startyint+(cy*16*mapscreen_single_scale), 16*mapscreen_single_scale, 16*mapscreen_single_scale, x, y);
9920 }
9921 }
9922 }
9923
9924 {
9925 size_and_pos* squares[4] = {&itemsqr_pos,&stairsqr_pos,&warparrival_pos,&flagsqr_pos};
9926 for(int32_t j=0; j<4; j++)
9927 {
9928 auto& square = *squares[j];
9929 if(square.rect(x,y))
9930 {
9931 char msg[160];
9932 sprintf(msg,
9933 j==0 ? "Item Location" :
9934 j==1 ? "Stairs Secret\nTriggered when a Trigger Push Block is pushed." :
9935 j==2 ? "Arrival Square\nPlayer's location when they begin/resume the game." :
9936 "Combo Flags");
9937 update_tooltip(x,y,square,msg);
9938 }
9939 }
9940
9941 // Warp Returns
9942 for(int32_t j=0; j<4; j++)
9943 {
9944 size_and_pos& wret = warpret_pos[j];
9945 if(wret.rect(x,y))
9946 {
9947 char msg[160];
9948 sprintf(msg,"Warp Return Square %c\nPlayer's destination after warping to this screen.",(char)('A'+j));
9949 update_tooltip(x,y,wret,msg);
9950 }
9951 }
9952
9953 // Enemies
9954 if(enemy_prev_pos.rect(x,y))
9955 {
9956 char msg[160];
9957 sprintf(msg,"Enemies that appear on this screen.");
9958 update_tooltip(x,y,enemy_prev_pos,msg);
9959 }
9960
9961 int32_t cmd = commands_list.rectind(x,y);
9962 if(cmd > -1)
9963 {
9964 update_tooltip(x,y,commands_list.subsquare(cmd),
9965 fmt::format("Fav Command {}: {}\n{}", cmd,
9966 get_hotkey_name(favorite_commands[cmd]),
9967 get_hotkey_helptext(favorite_commands[cmd])).c_str());
9968 }
9969 }
9970
9971 if(draw_mode==dm_alias)
9972 {
9973 for(int32_t j=0; j<num_combo_cols; ++j)
9974 {
9975 auto& sqr = comboaliaslist[j];
9976 auto ind = sqr.rectind(x,y);
9977 if(ind > -1)
9978 {
9979 auto c2=ind+combo_alistpos[j];
9980 char msg[80];
9981 sprintf(msg, "Combo alias %d", c2);
9982 update_tooltip(x,y,sqr.subsquare(ind), msg);
9983 }
9984 }
9985 }
9986 else if(draw_mode==dm_cpool)
9987 {
9988 for(int32_t j=0; j<num_combo_cols; ++j)
9989 {
9990 auto& sqr = comboaliaslist[j];
9991 auto ind = sqr.rectind(x,y);
9992 if(ind > -1)
9993 {
9994 auto c2=ind+combo_pool_listpos[j];
9995 char msg[80];
9996 sprintf(msg, "Combo Pool %d", c2);
9997 update_tooltip(x,y,sqr.subsquare(ind), msg);
9998 }
9999 }
10000 if(cpool_prev_visible && combopool_prevbtn.rect(x,y))
10001 {
10002 if(do_layer_button_reset(combopool_prevbtn.x,combopool_prevbtn.y,
10003 combopool_prevbtn.w,combopool_prevbtn.h,
10004 weighted_cpool ? "Weighted" : "Unweighted",0,true))
10005 {
10006 weighted_cpool = !weighted_cpool;
10007 }
10008 }
10009 }
10010 else if (draw_mode == dm_auto)
10011 {
10012 for (int32_t j = 0; j < num_combo_cols; ++j)
10013 {
10014 auto& sqr = comboaliaslist[j];
10015 auto ind = sqr.rectind(x, y);
10016 if (ind > -1)
10017 {
10018 auto c2 = ind + combo_auto_listpos[j];
10019 char msg[80];
10020 sprintf(msg, "Auto Combo %d", c2);
10021 update_tooltip(x, y, sqr.subsquare(ind), msg);
10022 }
10023 }
10024 }
10025 else
10026 {
10027 if(combo_preview.rect(x,y))
10028 {
10029 auto str = "Combo Colors:\n"+get_combo_colornames(Combo,CSet);
10030 update_tooltip(x,y,combo_preview,str.c_str());
10031 }
10032 else if(comboprev_buf[0] && combo_preview_text1.rect(x,y))
10033 {
10034 update_tooltip(x,y,combo_preview_text1,comboprev_buf);
10035 }
10036 else if(comboprev_buf2[0] && combo_preview_text2.rect(x,y))
10037 {
10038 update_tooltip(x,y,combo_preview_text2,comboprev_buf2);
10039 }
10040 else for(int32_t j=0; j<num_combo_cols; ++j)
10041 {
10042 auto& sqr = combolist[j];
10043 auto ind = sqr.rectind(x,y);
10044 if(ind > -1)
10045 {
10046 int32_t c2=ind+First[j];
10047 std::ostringstream oss;
10048 newcombo const& cmb = combobuf[c2];
10049 oss << "Combo " << c2 << ": " << combo_class_buf[cmb.type].name;
10050 if(cmb.flag != 0)
10051 oss << "\nInherent flag: " << ZI.getMapFlagName(cmb.flag);
10052 if(!cmb.label.empty())
10053 oss << "\nLabel: " << cmb.label;
10054
10055 update_tooltip(x,y,sqr.subsquare(ind), oss.str().c_str());
10056 }
10057 }
10058 }
10059
10060 if (favorites_list.rect(x, y))
10061 {
10062 int32_t f = favorites_list.rectind(x, y);
10063 int32_t row = f / favorites_list.w;
10064 int32_t col = f % favorites_list.w;
10065 f = (row * FAVORITECOMBO_PER_ROW) + col;
10066
10067 auto& sqr = favorites_list.subsquare(col, row);
10068
10069 char buf[180];
10070 if (favorite_combos[f] == -1)
10071 sprintf(buf, "Fav Combo %d\nEmpty", f);
10072 else
10073 {
10074 switch (favorite_combo_modes[f])
10075 {
10076 case dm_alias:
10077 sprintf(buf, "Fav Combo %d\nAlias %d", f, favorite_combos[f]);
10078 break;
10079 case dm_cpool:
10080 sprintf(buf, "Fav Combo %d\nPool %d", f, favorite_combos[f]);
10081 break;
10082 case dm_auto:
10083 sprintf(buf, "Fav Combo %d\nAutocombo %d", f, favorite_combos[f]);
10084 break;
10085 default:
10086 sprintf(buf, "Fav Combo %d\nCombo %d", f, favorite_combos[f]);
10087 }
10088 }
10089 update_tooltip(x, y, sqr, buf);
10090 }
10091
10092 size_and_pos const& real_mini = zoomed_minimap ? real_minimap_zoomed : real_minimap;
10093 auto ind = real_mini.rectind(x,y);
10094 if(ind > -1)
10095 {
10096 char buf[80];
10097 sprintf(buf,"0x%02X (%d)", ind, ind);
10098 ttip_install(minimap_tooltip_id, buf, real_mini.subsquare(ind), real_mini.x+real_mini.tw(), real_mini.y-16);
10099 ttip_set_highlight_thickness(minimap_tooltip_id, zoomed_minimap ? 2 : 1);
10100 // Make sure always above the other tooltip items to the right of the map (even in big map mode).
10101 ttip_set_z_index(minimap_tooltip_id, 100);
10102 ttip_clear_timer();
10103 }
10104 else
10105 {
10106 ttip_uninstall(minimap_tooltip_id);
10107 }
10108
10109 // Mouse clicking stuff
10110 int real_mb = gui_mouse_b();
10111 int mb = real_mb & ~mouse_down; //Only handle clicks that have not been handled already
10112 auto mz = mouse_z;
10113 bool lclick = mb&1;
10114 bool rclick = mb&2;
10115
10116 if (mb && hotkeys_is_active())
10117 {
10118 hotkeys_toggle_display(false);
10119 while (gui_mouse_b())
10120 {
10121 custom_vsync();
10122 }
10123 return;
10124 }
10125
10126 FONT* tfont = font;
10127 if(zoomed_minimap)
10128 {
10129 if((lclick||rclick) && !minimap_zoomed.rect(x,y))
10130 {
10131 // 'Clicked off'
10132 mmap_set_zoom(false);
10133 goto domouse_doneclick;
10134 }
10135 }
10136
10137 if(real_mb==0)
10138 {
10139 mouse_down = 0;
10140 canfill=true;
10141 }
10142 else if(lclick || rclick)
10143 {
10144 //on the minimap
10145 if(real_mini.rect(x,y))
10146 {
10147 if(lclick)
10148 select_scr();
10149 else if(rclick && !(mouse_down&2))
10150 {
10151 mmap_set_zoom(!zoomed_minimap);
10152 }
10153 goto domouse_doneclick;
10154 }
10155
10156 if(zoomed_minimap && minimap_zoomed.rect(x,y))
10157 goto domouse_doneclick; //Eat clicks
10158
10159 //on the map tabs
10160 font = get_custom_font(CFONT_GUI);
10161 for(int32_t btn=0; btn<mappage_count; ++btn)
10162 {
10163 char tbuf[15];
10164 sprintf(tbuf, "%d:%02X", map_page[btn].map+1, map_page[btn].screen);
10165 auto& sqr = map_page_bar[btn];
10166 if(sqr.rect(x,y))
10167 {
10168 if(do_layer_button_reset(sqr.x,sqr.y,sqr.w,sqr.h,tbuf,(btn==current_mappage?D_SELECTED:0)))
10169 {
10170 draw_layer_button(screen, sqr.x,sqr.y,sqr.w,sqr.h,tbuf,D_SELECTED);
10171 map_page[current_mappage].map=Map.getCurrMap();
10172 map_page[current_mappage].screen=Map.getCurrScr();
10173 current_mappage=btn;
10174 Map.setCurrMap(map_page[current_mappage].map);
10175 Map.setCurrScr(map_page[current_mappage].screen);
10176 rebuild_trans_table(); //Woo
10177 }
10178 goto domouse_doneclick;
10179 }
10180 }
10181
10182 if(compactbtn.rect(x,y))
10183 {
10184 if(do_text_button(compactbtn.x, compactbtn.y, compactbtn.w, compactbtn.h, is_compact ? "< Expand" : "> Compact"));
10185 toggle_is_compact();
10186 goto domouse_doneclick;
10187 }
10188
10189 if(!zoom_in_btn_disabled && zoominbtn.rect(x,y))
10190 {
10191 if(do_text_button(zoominbtn.x, zoominbtn.y, zoominbtn.w, zoominbtn.h, "+"))
10192 change_mapscr_zoom(-1);
10193 goto domouse_doneclick;
10194 }
10195
10196 if(!zoom_out_btn_disabled && zoomoutbtn.rect(x,y))
10197 {
10198 if(do_text_button(zoomoutbtn.x, zoomoutbtn.y, zoomoutbtn.w, zoomoutbtn.h, "-"))
10199 change_mapscr_zoom(1);
10200 goto domouse_doneclick;
10201 }
10202
10203 font = get_zc_font(font_lfont_l);
10204 if(combo_merge_btn.rect(x,y))
10205 {
10206 bool merged = is_compact ? compact_merged_combopane : large_merged_combopane;
10207 if(do_text_button(combo_merge_btn.x,combo_merge_btn.y,combo_merge_btn.w,combo_merge_btn.h,merged ? "<|>" : ">|<"))
10208 {
10209 toggle_merged_mode();
10210 }
10211 goto domouse_doneclick;
10212 }
10213
10214 if(favorites_zoombtn.rect(x,y))
10215 {
10216 bool zoomed = is_compact ? compact_zoomed_fav : large_zoomed_fav;
10217 if(do_text_button(favorites_zoombtn.x,favorites_zoombtn.y,favorites_zoombtn.w,favorites_zoombtn.h,zoomed ? "-" : "+"))
10218 {
10219 toggle_favzoom_mode();
10220 }
10221 goto domouse_doneclick;
10222 }
10223 else if(favorites_x.rect(x,y))
10224 {
10225 if(do_text_button(favorites_x.x,favorites_x.y,favorites_x.w,favorites_x.h,"X"))
10226 {
10227 AlertDialog("Clear Favorite Combos",
10228 "Are you sure you want to clear all favorite combos?",
10229 [&](bool ret,bool)
10230 {
10231 if(ret)
10232 {
10233 for(auto q = 0; q < MAXFAVORITECOMBOS; ++q)
10234 {
10235 favorite_combos[q] = -1;
10236 favorite_combo_modes[q] = dm_normal;
10237 }
10238 saved = false;
10239 refresh(rFAVORITES);
10240 }
10241 }).show();
10242 }
10243 goto domouse_doneclick;
10244 }
10245 else if(favorites_infobtn.rect(x,y))
10246 {
10247 if(do_text_button(favorites_infobtn.x,favorites_infobtn.y,favorites_infobtn.w,favorites_infobtn.h,"?"))
10248 {
10249 InfoDialog("Favorite Combos",
10250 "On LClick (empty): Sets clicked favorite to the current combo."
10251 "\nOn LClick: Sets current combo to clicked favorite."
10252 "\nShift+LClick: Sets clicked favorite to current combo."
10253 "\nCtrl+LClick: Clears clicked favorite."
10254 "\nAlt+LClick: Scrolls to clicked favorite."
10255 "\nRClick: Opens context menu."
10256 "\n\nClick the Page buttons (<-/->) to cycle between pages (RClick to jump to a page)"
10257 "\nClick the Zoom button (+/-) to toggle zoom level."
10258 "\nClick the X button to clear all favorite combos.").show();
10259 }
10260 goto domouse_doneclick;
10261 }
10262 else if(favorites_pgleft.rect(x,y))
10263 {
10264 if (do_text_button(favorites_pgleft.x, favorites_pgleft.y, favorites_pgleft.w, favorites_pgleft.h, is_compact ? "<" : "<-"))
10265 {
10266 if (rclick)
10267 {
10268 if(auto val = popup_num_menu(x, y, 1, 9, FavoriteComboPage, [](int p){return fmt::format("Page {}",p);}))
10269 FavoriteComboPage = vbound(*val-1, 0, 8);
10270 }
10271 else
10272 FavoriteComboPage = FavoriteComboPage == 0 ? 8 : --FavoriteComboPage;
10273 reload_zq_gui();
10274 }
10275 goto domouse_doneclick;
10276 }
10277 else if(favorites_pgright.rect(x,y))
10278 {
10279 if (do_text_button(favorites_pgright.x, favorites_pgright.y, favorites_pgright.w, favorites_pgright.h, is_compact ? ">" : "->"))
10280 {
10281 if (rclick)
10282 {
10283 if(auto val = popup_num_menu(x, y, 1, 9, FavoriteComboPage, [](int p){return fmt::format("Page {}",p);}))
10284 FavoriteComboPage = vbound(*val-1, 0, 8);
10285 }
10286 else
10287 FavoriteComboPage = FavoriteComboPage == 8 ? 0 : ++FavoriteComboPage;
10288 reload_zq_gui();
10289 }
10290 goto domouse_doneclick;
10291 }
10292
10293 if(commands_zoombtn.rect(x,y))
10294 {
10295 bool zoomed = is_compact ? compact_zoomed_cmd : large_zoomed_cmd;
10296 if(do_text_button(commands_zoombtn.x,commands_zoombtn.y,commands_zoombtn.w,commands_zoombtn.h,zoomed ? "-" : "+"))
10297 {
10298 toggle_cmdzoom_mode();
10299 }
10300 goto domouse_doneclick;
10301 }
10302 else if(commands_x.rect(x,y))
10303 {
10304 if(do_text_button(commands_x.x,commands_x.y,commands_x.w,commands_x.h,"X"))
10305 {
10306 AlertDialog("Clear Favorite Commands",
10307 "Are you sure you want to clear all favorite commands?",
10308 [&](bool ret,bool)
10309 {
10310 if(ret)
10311 {
10312 char buf[20];
10313 for(auto q = 0; q < MAXFAVORITECOMMANDS; ++q)
10314 {
10315 write_fav_command(q,0);
10316 }
10317 refresh(rFAVORITES);
10318 }
10319 }).show();
10320 }
10321 goto domouse_doneclick;
10322 }
10323 else if(commands_infobtn.rect(x,y))
10324 {
10325 if(do_text_button(commands_infobtn.x,commands_infobtn.y,commands_infobtn.w,commands_infobtn.h,"?"))
10326 {
10327 InfoDialog("Favorite Commands",
10328 "On LClick (empty): Choose a favorite command"
10329 "\nOn LClick: Runs the favorite command"
10330 "\nShift+Click: Choose a favorite command"
10331 "\nRClick: Choose a favorite command"
10332 "\nCtrl+Click: Clears clicked command"
10333 "\nAlt+Click: Shows info on the favorite command"
10334 "\n\nClick the Zoom button (+/-) to toggle zoom level"
10335 "\nClick the X button to clear all favorite commands").show();
10336 }
10337 goto domouse_doneclick;
10338 }
10339 font=tfont;
10340
10341 // On the layer panel
10342 font = get_custom_font(CFONT_GUI);
10343 for(int32_t i=0; i<=6; ++i)
10344 {
10345 int32_t spacing_offs = is_compact ? 2 : 10;
10346 int32_t rx = (i * (layerpanel_buttonwidth+spacing_offs+layerpanel_checkbox_wid)) + layer_panel.x+(is_compact?2:6);
10347 int32_t ry = layer_panel.y;
10348
10349 if ((i == 0 || mapscreen_valid_layers[i - 1]) && isinRect(x,y,rx,ry,rx+layerpanel_buttonwidth-1,ry+layerpanel_buttonheight-1))
10350 {
10351 char tbuf[15];
10352
10353 if (Map.getViewSize() > 1)
10354 {
10355 sprintf(tbuf, "%d", i);
10356 }
10357 else if (i != 0 && mapscreen_valid_layers[i - 1])
10358 {
10359 if (is_compact)
10360 {
10361 sprintf(tbuf, "%s%d %d:%02X",
10362 (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"",
10363 i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
10364 }
10365 else
10366 {
10367 sprintf(tbuf, "%s%d (%d:%02X)",
10368 (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"",
10369 i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
10370 }
10371 }
10372 else
10373 {
10374 sprintf(tbuf, "%d", i);
10375 }
10376
10377 if(do_text_button(rx, ry, layerpanel_buttonwidth, layerpanel_buttonheight, tbuf))
10378 {
10379 CurrentLayer = i;
10380 goto domouse_doneclick;
10381 }
10382 }
10383
10384 auto cbyofs = (layerpanel_buttonheight-layerpanel_checkbox_hei)/2;
10385 if(isinRect(x,y,rx+layerpanel_buttonwidth+1,ry+cbyofs,rx+layerpanel_buttonwidth+1+layerpanel_checkbox_wid-1,ry+2+layerpanel_checkbox_hei-1))
10386 {
10387 do_checkbox(menu1,rx+layerpanel_buttonwidth+1,ry+cbyofs,layerpanel_checkbox_wid,layerpanel_checkbox_hei,LayerMaskInt[i]);
10388 goto domouse_doneclick;
10389 }
10390 }
10391 font=tfont;
10392
10393 //Uses lclick/rclick separately
10394
10395 //on the map screen
10396 if(isinRect(x,y,startxint,startyint,startxint+(256*mapscreen_screenunit_scale)-1,startyint+(176*mapscreen_screenunit_scale)-1))
10397 {
10398 if (lclick)
10399 {
10400 Map.setCurrScr(Map.getScreenForPosition(combo_pos));
10401 }
10402
10403 if (draw_mode == dm_auto)
10404 {
10405 if (CHECK_CTRL_CMD)
10406 {
10407 if (canfill)
10408 {
10409 switch (fill_type)
10410 {
10411 case 0:
10412 flood();
10413 break;
10414
10415 case 1:
10416 fill_4();
10417 break;
10418
10419 case 2:
10420 fill_8();
10421 break;
10422
10423 case 3:
10424 fill2_4();
10425 break;
10426
10427 case 4:
10428 fill2_8();
10429 break;
10430 }
10431
10432 canfill = false;
10433 }
10434 }
10435 else
10436 draw(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10437 }
10438 else if (scr && lclick)
10439 {
10440 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
10441 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
10442
10443 // Move items
10444 if (scr->hasitem && active_visible_screen)
10445 {
10446 int32_t ix = scr->itemx + active_visible_screen->dx * 256;
10447 int32_t iy = scr->itemy + active_visible_screen->dy * 176;
10448
10449 if(cx2 >= ix && cx2 < ix+16 && cy2 >= iy && cy2 < iy+16)
10450 doxypos(scr->itemx, scr->itemy, 11, SNAP_HALF, SNAP_NONE, true, 0, 0, 16, 16);
10451 }
10452
10453 // Move FFCs
10454 int num_ffcs = scr->numFFC();
10455 for(int32_t i=num_ffcs-1; i>=0; i--)
10456 if(scr->ffcs[i].data !=0 && (scr->ffcs[i].layer >= CurrentLayer || (scr->ffcs[i].flags&ffc_overlay)))
10457 {
10458 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
10459 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
10460
10461 if(cx2 >= ffx && cx2 < ffx+(scr->ffTileWidth(i)*16) && cy2 >= ffy && cy2 < ffy+(scr->ffTileHeight(i)*16))
10462 {
10463 moveffc(i, cx2, cy2);
10464 break;
10465 }
10466 }
10467
10468 if(key[KEY_ALT]||key[KEY_ALTGR])
10469 {
10470 if (!draw_mapscr) return;
10471
10472 Combo=draw_mapscr->data[c];
10473 if(AutoBrush)
10474 BrushWidth = BrushHeight = 1;
10475 if(key[KEY_LSHIFT]||key[KEY_RSHIFT])
10476 CSet=draw_mapscr->cset[c];
10477 if(CHECK_CTRL_CMD)
10478 First[current_combolist]=scrollto_cmb(draw_mapscr->data[c]);
10479 }
10480 else if(CHECK_CTRL_CMD)
10481 {
10482 if(canfill)
10483 {
10484 switch(fill_type)
10485 {
10486 case 0:
10487 flood();
10488 break;
10489
10490 case 1:
10491 fill_4();
10492 break;
10493
10494 case 2:
10495 fill_8();
10496 break;
10497
10498 case 3:
10499 fill2_4();
10500 break;
10501
10502 case 4:
10503 fill2_8();
10504 break;
10505 }
10506
10507 canfill=false;
10508 }
10509 }
10510 else draw(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10511 }
10512 else if (scr && rclick)
10513 {
10514 ComboBrushPause=1;
10515 refresh(rMAP);
10516 restore_mouse();
10517 ComboBrushPause=0;
10518
10519 bool clickedffc = false;
10520
10521 // FFC right-click menu
10522 // This loop also serves to find the free ffc with the smallest slot number.
10523 int num_ffcs = scr->numFFC();
10524 uint32_t earliestfreeffc = num_ffcs;
10525 for(int32_t i=num_ffcs-1; i>=0; i--)
10526 {
10527 auto data = scr->ffcs[i].data;
10528 if(data==0)
10529 {
10530 if(i < earliestfreeffc)
10531 earliestfreeffc = i;
10532 continue;
10533 }
10534
10535 if(clickedffc || !(scr->valid&mVALID))
10536 continue;
10537
10538 if(data!=0 && (scr->ffcs[i].layer >= CurrentLayer || (scr->ffcs[i].flags&ffc_overlay)))
10539 {
10540 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
10541 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
10542 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
10543 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
10544
10545 if(cx2 >= ffx && cx2 < ffx+(scr->ffTileWidth(i)*16) && cy2 >= ffy && cy2 < ffy+(scr->ffTileHeight(i)*16))
10546 {
10547 NewMenu rcmenu
10548 {
10549 { "Copy FFC", [&](){Map.CopyFFC(active_visible_screen->screen, i);} },
10550 { "Paste FFC data", [&]()
10551 {
10552 bool didconfirm = false;
10553 AlertDialog("Confirm Paste",
10554 "Really replace the FFC with the data of the copied FFC?",
10555 [&](bool ret,bool)
10556 {
10557 if(ret)
10558 didconfirm = true;
10559 }).show();
10560 if(didconfirm)
10561 {
10562 auto set_ffc_data = Map.getCopyFFCData();
10563 set_ffc_data.x = scr->ffcs[i].x;
10564 set_ffc_data.y = scr->ffcs[i].y;
10565 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, set_ffc_data);
10566 }
10567 }, nullopt, Map.getCopyFFC() < 0 },
10568 { "Edit FFC", [&](){call_ffc_dialog(i, active_visible_screen->scr, active_visible_screen->screen);} },
10569 { "Clear FFC", [&]()
10570 {
10571 bool didconfirm = false;
10572 AlertDialog("Confirm Clear",
10573 "Really clear this Freeform Combo?",
10574 [&](bool ret,bool)
10575 {
10576 if(ret)
10577 didconfirm = true;
10578 }).show();
10579 if(didconfirm)
10580 {
10581 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, {
10582 .x = 0,
10583 .y = 0,
10584 .vx = 0,
10585 .vy = 0,
10586 .ax = 0,
10587 .ay = 0,
10588 .data = 0,
10589 .cset = 0,
10590 .delay = 0,
10591 .link = 0,
10592 .script = 0,
10593 .tw = 1,
10594 .th = 1,
10595 .ew = 16,
10596 .eh = 16,
10597 .flags = ffc_none,
10598 .initd = 0,
10599 });
10600 saved = false;
10601 }
10602 } },
10603 { "Snap to Grid", [&]()
10604 {
10605 int oldffx = scr->ffcs[i].x.getInt();
10606 int oldffy = scr->ffcs[i].y.getInt();
10607 int pos = COMBOPOS(oldffx,oldffy);
10608 int newffy = COMBOY(pos);
10609 int newffx = COMBOX(pos);
10610
10611 auto set_ffc_data = set_ffc_command::create_data(scr->ffcs[i]);
10612 set_ffc_data.x = newffx;
10613 set_ffc_data.y = newffy;
10614 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, set_ffc_data);
10615
10616 saved = false;
10617 } },
10618 };
10619 rcmenu.pop(x, y);
10620 clickedffc = true;
10621 break;
10622 }
10623 }
10624 }
10625
10626 // Combo right-click menu
10627 if(!clickedffc)
10628 {
10629 int warpindex = Map.warpindex(scr->data[c]);
10630 string txt_twarp_follow, txt_twarp_edit, txt_ffc_edit, txt_ffc_paste;
10631 bool show_ffcs = earliestfreeffc < MAXFFCS;
10632 bool dis_paste_ffc = Map.getCopyFFC() < 0;
10633 bool show_warps = warpindex > -1;
10634 bool show_warpback = Map.has_warpback();
10635 // FFC-specific options
10636 if(earliestfreeffc < MAXFFCS)
10637 {
10638 txt_ffc_edit = fmt::format("Edit New FFC {}",earliestfreeffc+1);
10639 if(Map.getCopyFFC()>-1)
10640 txt_ffc_paste = fmt::format("Paste FFC as FFC {}",earliestfreeffc+1);
10641 else
10642 txt_ffc_paste = "Paste FFC";
10643 }
10644
10645 if(warpindex > -1)
10646 {
10647 char letter = warpindex==4 ? 'R' : 'A'+warpindex;
10648 txt_twarp_follow = fmt::format("Follow Tile Warp {}",letter);
10649 txt_twarp_edit = fmt::format("Edit Tile Warp {}",letter);
10650 }
10651
10652 NewMenu draw_rc_menu
10653 {
10654 { "Select Combo", [&]()
10655 {
10656 Combo = draw_mapscr->data[c];
10657 if(AutoBrush)
10658 BrushWidth = BrushHeight = 1;
10659 }, nullopt, !draw_mapscr },
10660 { "Scroll to Combo", [&]()
10661 {
10662 First[current_combolist] = scrollto_cmb(draw_mapscr->data[c]);
10663 }, nullopt, !draw_mapscr },
10664 { "Edit Combo", [&]()
10665 {
10666 edit_combo(draw_mapscr->data[c],true,draw_mapscr->cset[c]);
10667 }, nullopt, !draw_mapscr },
10668 {},
10669 { "Replace All", [&](){replace(combo_pos);} },
10670 { "Draw Block", &draw_block_menu },
10671 { "Brush Settings ", &brush_menu },
10672 { "Set Fill Type ", &fill_menu },
10673 };
10674 if(show_warps || show_warpback)
10675 {
10676 draw_rc_menu.add_sep();
10677 if(show_warpback)
10678 draw_rc_menu.add({ "Warp Back", [&](){Map.warpback();} });
10679 if(show_warps)
10680 {
10681 draw_rc_menu.add({ txt_twarp_follow, [&](){follow_twarp(warpindex);} });
10682 draw_rc_menu.add({ txt_twarp_edit, [&](){edit_twarp(warpindex);} });
10683 }
10684 }
10685 if(show_ffcs)
10686 {
10687 draw_rc_menu.add_sep();
10688 draw_rc_menu.add({ txt_ffc_edit, [&]()
10689 {
10690 ffdata tempdat;
10691 // x, y are ints on ffdata (but ffc x, y are zfix), so *10000
10692 tempdat.x = ((int((x-startxint)/mapscreen_single_scale)&(~0x0007)) % 256) * 10000;
10693 tempdat.y = ((int((y-startyint)/mapscreen_single_scale)&(~0x0007)) % 176) * 10000;
10694 tempdat.data = Combo;
10695 tempdat.cset = CSet;
10696 call_ffc_dialog(earliestfreeffc, tempdat, active_visible_screen->scr, active_visible_screen->screen);
10697 } });
10698 draw_rc_menu.add({ txt_ffc_paste, [&]()
10699 {
10700 auto set_ffc_data = Map.getCopyFFCData();
10701 set_ffc_data.x = ((int((x-startxint)/mapscreen_single_scale)&(~0x0007)) % 256);
10702 set_ffc_data.y = ((int((y-startyint)/mapscreen_single_scale)&(~0x0007)) % 176);
10703 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, earliestfreeffc, set_ffc_data);
10704 }, nullopt, dis_paste_ffc });
10705 }
10706 draw_rc_menu.add_sep();
10707 draw_rc_menu.add({ "Screen", &rc_menu_screen });
10708 draw_rc_menu.pop(x,y);
10709 }
10710 }
10711 goto domouse_doneclick;
10712 }
10713
10714 //on the drawing mode button
10715 font = get_custom_font(CFONT_GUI);
10716 if(drawmode_btn.rect(x,y))
10717 {
10718 if(lclick)
10719 {
10720 if(do_text_button(drawmode_btn.x,drawmode_btn.y,drawmode_btn.w,drawmode_btn.h,dm_names[draw_mode]))
10721 onDrawingMode();
10722 }
10723 else if(rclick)
10724 drawing_mode_menu.pop(x,y);
10725 goto domouse_doneclick;
10726 }
10727 font=tfont;
10728
10729 //Squares
10730 //
10731 set_active_visible_screen(Map.CurrScr());
10732 {
10733 if(squarepanel_swap_btn.rect(x,y))
10734 {
10735 toggle_compact_sqr_mode();
10736 goto domouse_doneclick;
10737 }
10738 if(squarepanel_up_btn.rect(x,y))
10739 {
10740 cycle_compact_sqr(false);
10741 goto domouse_doneclick;
10742 }
10743 if(squarepanel_down_btn.rect(x,y))
10744 {
10745 cycle_compact_sqr(true);
10746 goto domouse_doneclick;
10747 }
10748
10749 bool do_dummyxy = false;
10750 bool dummymode = key[KEY_LSHIFT] || key[KEY_RSHIFT];
10751
10752 if(itemsqr_pos.rect(x,y))
10753 {
10754 if(dummymode) do_dummyxy = true;
10755 else
10756 {
10757 onItem();
10758
10759 if(!rclick && Map.CurrScr()->hasitem)
10760 doxypos(Map.CurrScr()->itemx,Map.CurrScr()->itemy,11,SNAP_HALF,SNAP_NONE);
10761 goto domouse_doneclick;
10762 }
10763 }
10764
10765 if(stairsqr_pos.rect(x,y))
10766 {
10767 if(dummymode) do_dummyxy = true;
10768 else
10769 {
10770 doxypos(Map.CurrScr()->stairx,Map.CurrScr()->stairy,14,SNAP_WHOLE);
10771 goto domouse_doneclick;
10772 }
10773 }
10774
10775 if(warparrival_pos.rect(x,y))
10776 {
10777 if(dummymode) do_dummyxy = true;
10778 else
10779 {
10780 if(get_qr(qr_NOARRIVALPOINT))
10781 {
10782 info_dsa("Arrival Square",
10783 "The arrival square cannot be used unless the QR 'Use Warp Return "
10784 "Points Only' under 'Quest->Options->Combos' is disabled."
10785 "\nGenerally, this square only exists for compatibility purposes, and is not used"
10786 " in creating new quests.",
10787 "dsa_warparrival");
10788 }
10789 else doxypos(Map.CurrScr()->warparrivalx,Map.CurrScr()->warparrivaly,10,SNAP_HALF,SNAP_NONE);
10790 goto domouse_doneclick;
10791 }
10792 }
10793
10794 if(flagsqr_pos.rect(x,y))
10795 {
10796 if(dummymode) do_dummyxy = true;
10797 else
10798 {
10799 onFlags();
10800 goto domouse_doneclick;
10801 }
10802 }
10803
10804 for(auto q = 0; q < 4; ++q)
10805 {
10806 if(warpret_pos[q].rect(x,y))
10807 {
10808 if(dummymode) do_dummyxy = true;
10809 else
10810 {
10811 doxypos(Map.CurrScr()->warpreturnx[q],Map.CurrScr()->warpreturny[q],9,SNAP_HALF,SNAP_NONE);
10812 goto domouse_doneclick;
10813 }
10814 }
10815 }
10816
10817 if(enemy_prev_pos.rect(x,y))
10818 {
10819 if(dummymode) do_dummyxy = true;
10820 else
10821 {
10822 onEnemies();
10823 goto domouse_doneclick;
10824 }
10825 }
10826
10827 if(do_dummyxy)
10828 {
10829 byte x = 0, y = 0;
10830 showxypos_dummy = true;
10831 doxypos(x,y,13,SNAP_HALF,SNAP_NONE);
10832 goto domouse_doneclick;
10833 }
10834 }
10835
10836 if(draw_mode==dm_alias)
10837 {
10838 for(int32_t j=0; j<num_combo_cols; ++j)
10839 {
10840 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10841 {
10842 scrollup(j);
10843 goto domouse_doneclick;
10844 }
10845 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10846 {
10847 scrolldown(j);
10848 goto domouse_doneclick;
10849 }
10850 else if(comboaliaslist[j].rect(x,y))
10851 {
10852 select_comboa(j);
10853
10854 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10855 popup_cpane_rc(x, y);
10856 goto domouse_doneclick;
10857 }
10858 }
10859 }
10860 else if(draw_mode==dm_cpool)
10861 {
10862 for(int32_t j=0; j<num_combo_cols; ++j)
10863 {
10864 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10865 {
10866 scrollup(j);
10867 goto domouse_doneclick;
10868 }
10869 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10870 {
10871 scrolldown(j);
10872 goto domouse_doneclick;
10873 }
10874 else if(comboaliaslist[j].rect(x,y))
10875 {
10876 select_combop(j);
10877
10878 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10879 popup_cpane_rc(x, y);
10880 goto domouse_doneclick;
10881 }
10882 }
10883 }
10884 else if (draw_mode == dm_auto)
10885 {
10886 for (int32_t j = 0; j < num_combo_cols; ++j)
10887 {
10888 if (combolistscrollers[j].rectind(x, y) == 0 && !mouse_down)
10889 {
10890 scrollup(j);
10891 goto domouse_doneclick;
10892 }
10893 else if (combolistscrollers[j].rectind(x, y) == 1 && !mouse_down)
10894 {
10895 scrolldown(j);
10896 goto domouse_doneclick;
10897 }
10898 else if (comboaliaslist[j].rect(x, y))
10899 {
10900 select_autocombo(j);
10901
10902 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10903 popup_cpane_rc(x, y);
10904 goto domouse_doneclick;
10905 }
10906 }
10907 }
10908 else
10909 {
10910 for(int32_t j=0; j<num_combo_cols; ++j)
10911 {
10912 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10913 {
10914 scrollup(j);
10915 goto domouse_doneclick;
10916 }
10917 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10918 {
10919 scrolldown(j);
10920 goto domouse_doneclick;
10921 }
10922 else if(combolist[j].rect(x,y))
10923 {
10924 select_combo(j);
10925
10926 if(rclick && combolist[j].rect(gui_mouse_x(),gui_mouse_y()))
10927 popup_cpane_rc(x, y);
10928 goto domouse_doneclick;
10929 }
10930 }
10931 }
10932
10933 //on the favorites list
10934 if(favorites_list.rect(x,y))
10935 {
10936 if(lclick)
10937 {
10938 int32_t f=favorites_list.rectind(x,y);
10939 int32_t row=f/favorites_list.w;
10940 int32_t col=f%favorites_list.w;
10941 f = (row*FAVORITECOMBO_PER_ROW)+col;
10942 int32_t fp = f + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
10943
10944 bool dmcond = favorite_combos[fp] < 0;
10945 if((key[KEY_LSHIFT] || key[KEY_RSHIFT] || dmcond) && !(CHECK_CTRL_CMD))
10946 {
10947 int32_t tempcb=ComboBrush;
10948 ComboBrush=0;
10949
10950 while(gui_mouse_b())
10951 {
10952 x=gui_mouse_x();
10953 y=gui_mouse_y();
10954
10955 switch(draw_mode)
10956 {
10957 case dm_alias:
10958 if (favorite_combos[fp] != combo_apos || favorite_combo_modes[fp] != dm_alias)
10959 {
10960 favorite_combo_modes[fp] = dm_alias;
10961 favorite_combos[fp] = combo_apos;
10962 saved = false;
10963 }
10964 break;
10965 case dm_cpool:
10966 if (favorite_combos[fp] != combo_pool_pos || favorite_combo_modes[fp] != dm_cpool)
10967 {
10968 favorite_combo_modes[fp] = dm_cpool;
10969 favorite_combos[fp] = combo_pool_pos;
10970 saved = false;
10971 }
10972 break;
10973 case dm_auto:
10974 if (favorite_combos[fp] != combo_auto_pos || favorite_combo_modes[fp] != dm_auto)
10975 {
10976 favorite_combo_modes[fp] = dm_auto;
10977 favorite_combos[fp] = combo_auto_pos;
10978 saved = false;
10979 }
10980 break;
10981 default:
10982 if (favorite_combos[fp] != Combo || favorite_combo_modes[fp] != dm_normal)
10983 {
10984 if (BrushWidth > 1 || BrushHeight > 1)
10985 {
10986 add_favorite_combo_block(f, Combo, key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10987 break;
10988 }
10989 favorite_combo_modes[fp] = dm_normal;
10990 favorite_combos[fp] = Combo;
10991 saved = false;
10992 }
10993 }
10994
10995 custom_vsync();
10996 refresh(rALL | rFAVORITES);
10997 }
10998
10999 ComboBrush=tempcb;
11000 }
11001 else if(CHECK_CTRL_CMD)
11002 {
11003 int32_t tempcb=ComboBrush;
11004 ComboBrush=0;
11005
11006 while(gui_mouse_b())
11007 {
11008 x=gui_mouse_x();
11009 y=gui_mouse_y();
11010
11011 if(favorite_combos[fp]!=-1)
11012 {
11013 favorite_combo_modes[fp] = dm_normal;
11014 favorite_combos[fp]=-1;
11015 saved=false;
11016 }
11017
11018 custom_vsync();
11019 refresh(rALL | rFAVORITES);
11020 }
11021
11022 ComboBrush=tempcb;
11023 }
11024 else if(key[KEY_ALT] || key[KEY_ALTGR])
11025 {
11026 if(select_favorite())
11027 {
11028 switch(favorite_combo_modes[fp])
11029 {
11030 case dm_alias:
11031 combo_alistpos[current_comboalist]=scrollto_alias(combo_apos);
11032 break;
11033 case dm_cpool:
11034 combo_pool_listpos[current_cpoollist] = scrollto_cpool(combo_pool_pos);
11035 break;
11036 case dm_auto:
11037 combo_auto_listpos[current_cautolist] = scrollto_cauto(combo_auto_pos);
11038 break;
11039 default:
11040 First[current_combolist]=scrollto_cmb(Combo);
11041 }
11042 }
11043 }
11044 else
11045 {
11046 select_favorite();
11047 }
11048 }
11049 else if(rclick)
11050 {
11051 bool valid=select_favorite();
11052
11053 if(valid)
11054 {
11055 int f = favorites_list.rectind(x,y);
11056 int row = f/favorites_list.w;
11057 int col = f%favorites_list.w;
11058 f = (row*FAVORITECOMBO_PER_ROW) + col + (FAVORITECOMBO_PER_PAGE * FavoriteComboPage);
11059 popup_favorites_rc(f, x, y);
11060 }
11061 }
11062 goto domouse_doneclick;
11063 }
11064
11065 //on the commands buttons
11066 int32_t cmd = commands_list.rectind(x,y);
11067 if(cmd > -1)
11068 {
11069 uint hkey = favorite_commands[cmd];
11070 bool shift=(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
11071 bool ctrl=(CHECK_CTRL_CMD);
11072 bool alt=(key[KEY_ALT] || key[KEY_ALTGR]);
11073 bool dis = disabled_hotkey(hkey);
11074 auto& btn = commands_list.subsquare(cmd);
11075 if(!dis||rclick||shift||ctrl||alt)
11076 {
11077 FONT *tfont=font;
11078 font=get_custom_font(CFONT_FAVCMD);
11079 if(do_layer_button_reset(btn.x,btn.y,btn.w,btn.h,
11080 get_hotkey_name(hkey),
11081 selected_hotkey(hkey)?D_SELECTED:0,
11082 true))
11083 {
11084 font=tfont;
11085 if(alt)
11086 {
11087 show_hotkey_info(hkey);
11088 }
11089 else if(ctrl)
11090 {
11091 write_fav_command(cmd,0);
11092 }
11093 else if(rclick || shift || hkey==ZQKEY_NULL_KEY)
11094 {
11095 if(auto newkey = select_fav_command())
11096 write_fav_command(cmd,*newkey);
11097 }
11098 else
11099 {
11100 run_hotkey(hkey);
11101 }
11102 }
11103
11104 font=tfont;
11105 }
11106 goto domouse_doneclick;
11107 }
11108 }
11109
11110 domouse_doneclick:
11111 mouse_down |= mb&3;
11112
11113 if(mouse_z!=0)
11114 {
11115 int32_t z=0;
11116
11117 for(int32_t j=0; j<num_combo_cols; ++j)
11118 {
11119 z=abs(mouse_z);
11120
11121 if(key[KEY_ALT]||key[KEY_ALTGR])
11122 {
11123 z*=combolist[j].h;
11124 }
11125
11126
11127 if(draw_mode == dm_alias)
11128 {
11129 if(comboaliaslist[j].rect(x,y))
11130 {
11131 if(mouse_z<0) //scroll down
11132 {
11133 combo_alistpos[current_comboalist] = zc_min(MAXCOMBOALIASES - comboaliaslist[j].w*comboaliaslist[j].h,
11134 combo_alistpos[current_comboalist]+comboaliaslist[j].w*z);
11135 }
11136 else //scroll up
11137 {
11138 if(combo_alistpos[current_comboalist]>0)
11139 {
11140 combo_alistpos[current_comboalist]-=zc_min(combo_alistpos[current_comboalist],comboaliaslist[j].w*z);
11141 }
11142 }
11143 goto domouse_donez;
11144 }
11145 }
11146 else if(draw_mode == dm_cpool)
11147 {
11148 if(comboaliaslist[j].rect(x,y))
11149 {
11150 if(mouse_z<0) //scroll down
11151 {
11152 combo_pool_listpos[current_cpoollist] = zc_min(MAXCOMBOPOOLS - comboaliaslist[j].w*comboaliaslist[j].h,
11153 combo_pool_listpos[current_cpoollist]+comboaliaslist[j].w*z);
11154 }
11155 else //scroll up
11156 {
11157 if(combo_pool_listpos[current_cpoollist]>0)
11158 {
11159 combo_pool_listpos[current_cpoollist]-=zc_min(combo_pool_listpos[current_cpoollist],comboaliaslist[j].w*z);
11160 }
11161 }
11162 goto domouse_donez;
11163 }
11164 }
11165 else if (draw_mode == dm_auto)
11166 {
11167 if (comboaliaslist[j].rect(x, y))
11168 {
11169 if (mouse_z < 0) //scroll down
11170 {
11171 combo_auto_listpos[current_cautolist] = zc_min(MAXAUTOCOMBOS - comboaliaslist[j].w * comboaliaslist[j].h,
11172 combo_auto_listpos[current_cautolist] + comboaliaslist[j].w * z);
11173 }
11174 else //scroll up
11175 {
11176 if (combo_auto_listpos[current_cautolist] > 0)
11177 {
11178 combo_auto_listpos[current_cautolist] -= zc_min(combo_auto_listpos[current_cautolist], comboaliaslist[j].w * z);
11179 }
11180 }
11181 goto domouse_donez;
11182 }
11183 }
11184 else
11185 {
11186 if(combolist[j].rect(x,y))
11187 {
11188 if(mouse_z<0) //scroll down
11189 {
11190 First[current_combolist] = zc_min(MAXCOMBOS-combolist[j].w*combolist[j].h,
11191 First[current_combolist] + combolist[j].w*z);
11192 }
11193 else //scroll up
11194 {
11195 if(First[current_combolist]>0)
11196 {
11197 First[current_combolist]-=zc_min(First[current_combolist],combolist[j].w*z);
11198 }
11199 }
11200 goto domouse_donez;
11201 }
11202 }
11203 }
11204
11205 z=abs(mouse_z);
11206
11207 if(real_mini.rect(x,y))
11208 {
11209 for(int32_t i=0; i<z; ++i)
11210 {
11211 if(mouse_z>0) onIncMap();
11212 else onDecMap();
11213 }
11214 goto domouse_donez;
11215 }
11216
11217 if(is_compact && compact_square_panels
11218 && squares_panel.rect(x,y))
11219 {
11220 cycle_compact_sqr(mouse_z < 0);
11221 goto domouse_donez;
11222 }
11223 domouse_donez:
11224 position_mouse_z(0);
11225 }
11226 font = tfont;
11227 active_visible_screen = nullptr;
11228 }
11229
11230 int32_t d_viewpal_proc(int32_t msg, DIALOG *d, int32_t c)
11231 {
11232 int32_t ret = d_bitmap_proc(msg, d, c);
11233 char* buf = (char*)d->dp2; //buffer to store the color code in
11234 DIALOG* d2 = (DIALOG*)d->dp3; //DIALOG* to update the text proc
11235 if(!buf)
11236 return ret;
11237 switch(msg)
11238 {
11239 case MSG_IDLE:
11240 case MSG_GOTMOUSE:
11241 case MSG_LOSTMOUSE:
11242 break;
11243 default:
11244 return ret;
11245 }
11246 char t[16];
11247 memcpy(t, buf, 16);
11248 int32_t x = gui_mouse_x() - d->x;
11249 int32_t y = gui_mouse_y() - d->y;
11250 if(msg != MSG_LOSTMOUSE && isinRect(x, y, 0, 0, d->w-1, d->h-1))
11251 {
11252 float palscale = 1.5;
11253 for(int32_t i = 0; i<256; ++i)
11254 if(isinRect(x,y,(int32_t)(((i&31)<<3)*palscale),(int32_t)(((i&0xE0)>>2)*palscale), (int32_t)((((i&31)<<3)+7)*palscale),(int32_t)((((i&0xE0)>>2)+7)*palscale)))
11255 {
11256 sprintf(buf, "0x%02X (%03d) ", i, i); //Extra spaces to increase drawn width, so it draws the blank area
11257 break;
11258 }
11259 }
11260 else memset(buf, ' ', 15);
11261 if(strcmp(buf, t) && d2 && d2->proc == jwin_text_proc && d2->dp == d->dp2)
11262 object_message(d2, MSG_DRAW, 0);
11263 return ret;
11264 }
11265
11266 static DIALOG showpal_dlg[] =
11267 {
11268 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11269 { jwin_win_proc, 24, 68, 272, 119, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "View Palette", NULL, NULL },
11270 { jwin_frame_proc, 30, 76+16, 260, 68, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
11271 { d_viewpal_proc, 32, 76+18, 256, 64, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11272 { jwin_text_proc, 32+8,76+18+66, 20, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
11273 { jwin_button_proc, 130, 144+18, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11274 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11275 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11276 };
11277
11278 int32_t onShowPal()
11279 {
11280 float palscale = 1.5;
11281
11282 BITMAP *palbmp = create_bitmap_ex(8,(int32_t)(256*palscale),(int32_t)(64*palscale));
11283
11284 if(!palbmp)
11285 return D_O_K;
11286 clear_to_color(palbmp,jwin_pal[jcBOX]); //If not cleared, random static appears between swatches! -E
11287 showpal_dlg[0].dp2=get_zc_font(font_lfont);
11288
11289 for(int32_t i=0; i<256; i++)
11290 rectfill(palbmp,(int32_t)(((i&31)<<3)*palscale),(int32_t)(((i&0xE0)>>2)*palscale), (int32_t)((((i&31)<<3)+7)*palscale),(int32_t)((((i&0xE0)>>2)+7)*palscale),i);
11291 showpal_dlg[2].dp=(void *)palbmp;
11292 char buf[16] = {0};
11293 showpal_dlg[2].dp2=(void *)buf;
11294 showpal_dlg[2].dp3=(void *)&(showpal_dlg[3]);
11295 showpal_dlg[3].dp=(void *)buf;
11296 showpal_dlg[3].dp2=(void *)get_zc_font(font_deffont);
11297
11298 large_dialog(showpal_dlg);
11299 do_zqdialog(showpal_dlg,2);
11300 destroy_bitmap(palbmp);
11301 return D_O_K;
11302 }
11303
11304 static DIALOG csetfix_dlg[] =
11305 {
11306 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11307 { jwin_win_proc, 72, 80, 176+1, 96+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "CSet Fix", NULL, NULL },
11308 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11309 { jwin_radio_proc, 104+22, 108, 80+1, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Full Screen", NULL, NULL },
11310 { jwin_radio_proc, 104+22, 118+2, 80+1, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Dungeon Floor", NULL, NULL },
11311 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
11312 { jwin_check_proc, 104+22, 128+4, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, (void *) "All Layers", NULL, NULL },
11313 { jwin_button_proc, 90, 152, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11314 { jwin_button_proc, 170, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11315 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11316 };
11317
11318 int32_t onCSetFix()
11319 {
11320 restore_mouse();
11321 csetfix_dlg[0].dp2=get_zc_font(font_lfont);
11322 int32_t s=2,x2=14,y2=9;
11323
11324 large_dialog(csetfix_dlg);
11325
11326 if(do_zqdialog(csetfix_dlg,-1)==6)
11327 {
11328 if(csetfix_dlg[2].flags&D_SELECTED)
11329 {
11330 s=0;
11331 x2=16;
11332 y2=11;
11333 }
11334
11335 if(csetfix_dlg[5].flags&D_SELECTED)
11336 {
11337 /*
11338 int32_t drawmap, drawscr;
11339 if (CurrentLayer==0)
11340 {
11341 drawmap=Map.getCurrMap();
11342 drawscr=Map.getCurrScr();
11343 }
11344 else
11345 {
11346 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
11347 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
11348 }
11349 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
11350 if(!draw_mapscr) return;
11351 saved=false;
11352 Map.Ugo();
11353
11354 if(!(draw_mapscr->valid&mVALID))
11355 {
11356 Map.CurrScr()->valid|=mVALID;
11357 draw_mapscr->valid|=mVALID;
11358 Map.setcolor(Color);
11359 }
11360 for(int32_t i=0; i<176; i++)
11361 {
11362 draw_mapscr->data[i]=Combo;
11363 draw_mapscr->cset[i]=CSet;
11364 }
11365 refresh(rMAP+rSCRMAP);
11366 */
11367 }
11368
11369 Map.StartListCommand();
11370 for(int32_t y=s; y<y2; y++)
11371 {
11372 for(int32_t x=s; x<x2; x++)
11373 {
11374 Map.DoSetComboCommand(Map.getCurrMap(), Map.getCurrScr(), (y<<4)+x, -1, CSet);
11375 }
11376 }
11377 Map.FinishListCommand();
11378
11379 refresh(rMAP);
11380 saved = false;
11381 }
11382
11383 return D_O_K;
11384 }
11385 static bool doAllSolidWater()
11386 {
11387 for(int32_t i=0; i < MAXCOMBOS; ++i)
11388 {
11389 if(combo_class_buf[combobuf[i].type].water!=0)
11390 {
11391 combobuf[i].walk |= 0x0F; //Solid
11392 }
11393 }
11394 return true;
11395 }
11396 static bool doNoSolidWater()
11397 {
11398 for(int32_t i=0; i < MAXCOMBOS; ++i)
11399 {
11400 if(combo_class_buf[combobuf[i].type].water!=0)
11401 {
11402 combobuf[i].walk &= ~0x0F; //Non-solid
11403 }
11404 }
11405 return true;
11406 }
11407 int32_t onWaterSolidity()
11408 {
11409 AlertFuncDialog("Water Conversion",
11410 "Forcibly set the solidity of all 'Liquid' combos in the quest?",
11411 ""
11412 ).add_buttons(2,
11413 { "Solid", "Non-Solid", "Cancel" },
11414 { doAllSolidWater, doNoSolidWater, nullptr }
11415 ).show();
11416 return D_O_K;
11417 }
11418
11419 static bool doAllEffectSquare()
11420 {
11421 for(int32_t i=0; i < MAXCOMBOS; ++i)
11422 {
11423 combobuf[i].walk |= 0xF0; //Effect
11424 }
11425 return true;
11426 }
11427 static bool doBlankEffectSquare()
11428 {
11429 for(int32_t i=0; i < MAXCOMBOS; ++i)
11430 {
11431 if(combobuf[i].is_blank(true))
11432 {
11433 combobuf[i].walk |= 0xF0; //Effect
11434 }
11435 }
11436 return true;
11437 }
11438
11439 int32_t onEffectFix()
11440 {
11441 AlertFuncDialog("Effect Square Conversion",
11442 "Forcibly fill the green effect square of all combos in the quest?",
11443 ""
11444 ).add_buttons(2,
11445 { "All", "Blank Only", "Cancel" },
11446 { doAllEffectSquare, doBlankEffectSquare, nullptr }
11447 ).show();
11448 return D_O_K;
11449 }
11450
11451 static bool clear_green_arrival_squares()
11452 {
11453 for(mapscr& scr : TheMaps)
11454 {
11455 if(!scr.valid) continue;
11456 scr.warparrivalx = 0;
11457 scr.warparrivaly = 0;
11458 }
11459 set_qr(qr_NOARRIVALPOINT, true);
11460 return true;
11461 }
11462
11463 static bool replace_green_arrival_squares()
11464 {
11465 // Check for conflicts first
11466 bool has_conflicts = false;
11467
11468 for(mapscr& scr : TheMaps)
11469 {
11470 if(!scr.valid) continue;
11471 if(!(scr.warparrivalx || scr.warparrivaly)) continue;
11472 if(scr.warpreturnx[0] || scr.warpreturny[0])
11473 {
11474 has_conflicts = true;
11475 break;
11476 }
11477 }
11478
11479 enum
11480 {
11481 NOT_ASKED = -1,
11482 MODE_FORCE, MODE_IGNORE, MODE_FIND_IGNORE, MODE_FIND_FORCE, MODE_CANCEL
11483 };
11484 int mode = NOT_ASKED;
11485
11486 if(has_conflicts)
11487 {
11488 AlertFuncDialog("Handle Conflicts",
11489 "Warp Square A is not available for all screens that have arrival squares."
11490 " How should this be handled? (See '?' for more info)",
11491 "Overwrite A: Replace the existing warp return square A with the position of the green arrival square"
11492 "\nIgnore: Do nothing if warp return square A exists"
11493 "\nFind Space or Ignore: Choose another, unused, square to set to the position of the green arrival square."
11494 " If none are unused, 'Ignore' instead."
11495 "\nFind Space or Overwrite: Choose another, unused square to set to the position of the green arrival square."
11496 " If none are unused, 'Overwrite A' instead."
11497 "\nCancel: Don't do anything"
11498 ).add_buttons(1,
11499 { "Overwrite A", "Ignore", "Find Space or Ignore", "Find Space or Overwrite A", "Cancel" },
11500 mode
11501 ).show();
11502 if(mode == NOT_ASKED || mode == MODE_CANCEL)
11503 return false;
11504 }
11505 for(mapscr& scr : TheMaps)
11506 {
11507 if(!scr.valid) continue;
11508 if(!(scr.warparrivalx || scr.warparrivaly)) continue;
11509 int indx = 0;
11510 if(scr.warpreturnx[0] || scr.warpreturny[0])
11511 {
11512 if(mode == MODE_IGNORE) continue; // Warp A not free, so ignore
11513 if(mode != MODE_FORCE)
11514 {
11515 for(int q = 1; q < 4; ++q)
11516 {
11517 if(scr.warpreturnx[q] || scr.warpreturny[q])
11518 continue;
11519 indx = q; // Use this warp, since it's free
11520 break;
11521 }
11522 if(indx == 0 && mode == MODE_FIND_IGNORE)
11523 continue; // Nothing free, so ignore
11524 }
11525 }
11526 scr.warpreturnx[indx] = scr.warparrivalx;
11527 scr.warpreturny[indx] = scr.warparrivaly;
11528 scr.warparrivalx = 0;
11529 scr.warparrivaly = 0;
11530 }
11531 set_qr(qr_NOARRIVALPOINT, true);
11532 return true;
11533 }
11534
11535 int32_t onRemoveOldArrivalSquare()
11536 {
11537 AlertFuncDialog("Arrival Square Removal",
11538 "Clear the old green 'Arrival' squares for the whole quest?"
11539 "\n(There will be no further confirmation, and this operation cannot be undone)",
11540 ""
11541 ).add_buttons(2,
11542 { "Replace With Blue Return Square", "Clear Completely", "Cancel" },
11543 { replace_green_arrival_squares, clear_green_arrival_squares, nullptr }
11544 ).show();
11545 return D_O_K;
11546 }
11547
11548 byte* getPalPointer(int32_t pal, int32_t cset)
11549 {
11550 if (pal < 0) return colordata + CSET(cset)*3;
11551 byte* ret = colordata + CSET(pal*pdLEVEL+poLEVEL)*3;
11552 switch(cset)
11553 {
11554 case 2: case 3: case 4:
11555 return ret + CSET(cset-2)*3;
11556 case 9:
11557 return ret + CSET(3)*3;
11558 case 1:
11559 return ret + CSET(13)*3;
11560 case 5:
11561 return ret + CSET(14)*3;
11562 case 7:
11563 return ret + CSET(15)*3;
11564 case 8:
11565 return ret + CSET(16)*3;
11566 }
11567 return NULL;
11568 }
11569
11570 void copyCSet(int32_t destpal, int32_t destcset, int32_t srcpal, int32_t srccset)
11571 {
11572 byte* dest = getPalPointer(destpal, destcset);
11573 byte* src = getPalPointer(srcpal, srccset);
11574 if (dest && src)
11575 {
11576 memcpy(dest, src, 16*3);
11577 }
11578 }
11579
11580 void setColorPalette(int32_t flags, int32_t lowpal, int32_t highpal)
11581 {
11582 for (auto q = lowpal; q <= highpal; ++q)
11583 {
11584 for (auto c = 0; c < 12; ++c)
11585 {
11586 if (!(flags&(1<<c))) continue;
11587 copyCSet(q, c, -1, c);
11588 }
11589 }
11590 }
11591
11592 void setPitDamage(int32_t flags, int32_t lowcombo, int32_t highcombo, int32_t damage)
11593 {
11594 for(int32_t i=lowcombo; i < highcombo; ++i)
11595 {
11596 if((combobuf[i].type == cPITFALL && (flags & (1<<0)))
11597 || (combobuf[i].type == cWATER && !(combobuf[i].usrflags & (1<<0)) && (flags & (1<<1)))
11598 || (combobuf[i].type == cWATER && (combobuf[i].usrflags & (1<<0)) && (flags & (1<<2))))
11599 {
11600 if ((combobuf[i].type != cPITFALL || (flags & (1<<9)) || !(combobuf[i].usrflags & (1<<0)))
11601 && ((flags & (1<<8)) || combobuf[i].attributes[0] == 0))
11602 combobuf[i].attributes[0] = damage*10000;
11603 }
11604 }
11605 }
11606
11607 static DIALOG template_dlg[] =
11608 {
11609 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11610 { jwin_win_proc, 72, 80, 176+1, 116+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "NES Dungeon Template", NULL, NULL },
11611 { d_comboframe_proc, 178, 122+3, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
11612 { d_combo_proc, 180, 124+3, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11613 // { d_bitmap_proc, 180, 104, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11614 { jwin_radio_proc, 104+33, 128+3, 64+1, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Floor:", NULL, NULL },
11615 { jwin_radio_proc, 104+33, 148+3, 64+1, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "No Floor", NULL, NULL },
11616 { jwin_button_proc, 90, 172, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11617 { jwin_button_proc, 170, 172, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11618 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11619 { jwin_text_proc, 104, 102, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "This copies the contents of", NULL, NULL },
11620 { jwin_text_proc, 104, 112, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "screen 83 of the current map.", NULL, NULL },
11621 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11622 };
11623
11624 int32_t onTemplate()
11625 {
11626 static bool donethis=false;
11627
11628 if(!donethis||!(key[KEY_LSHIFT]||key[KEY_RSHIFT]))
11629 {
11630 template_dlg[2].d1=Combo;
11631 template_dlg[2].fg=CSet;
11632 donethis=true;
11633 }
11634
11635 restore_mouse();
11636
11637 if(Map.getCurrScr()==TEMPLATE)
11638 return D_O_K;
11639
11640 // BITMAP *floor_bmp = create_bitmap_ex(8,16,16);
11641 // if(!floor_bmp) return D_O_K;
11642 template_dlg[0].dp2=get_zc_font(font_lfont);
11643 // put_combo(floor_bmp,0,0,Combo,CSet,0,0);
11644 // template_dlg[2].dp=floor_bmp;
11645
11646 large_dialog(template_dlg);
11647
11648 if(do_zqdialog(template_dlg,-1)==5)
11649 {
11650 saved=false;
11651 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
11652 Map.DoTemplateCommand((template_dlg[3].flags==D_SELECTED) ? template_dlg[2].d1 : -1, template_dlg[2].fg, screen);
11653 refresh(rMAP+rSCRMAP);
11654 }
11655
11656 // destroy_bitmap(floor_bmp);
11657 return D_O_K;
11658 }
11659
11660 int32_t d_sel_scombo_proc(int32_t msg, DIALOG *d, int32_t c)
11661 {
11662 //these are here to bypass compiler warnings about unused arguments
11663 c=c;
11664
11665 switch(msg)
11666 {
11667 case MSG_CLICK:
11668 while(gui_mouse_b())
11669 {
11670 int32_t x = zc_min(zc_max(gui_mouse_x() - d->x,0)>>4, 15);
11671 int32_t y = zc_min(zc_max(gui_mouse_y() - d->y,0)&0xF0, 160);
11672
11673 if(x+y != d->d1)
11674 {
11675 d->d1 = x+y;
11676 custom_vsync();
11677 d_sel_scombo_proc(MSG_DRAW,d,0);
11678 }
11679 }
11680
11681 break;
11682
11683 case MSG_DRAW:
11684 {
11685 blit((BITMAP*)(d->dp),screen,0,0,d->x,d->y,d->w,d->h);
11686 int32_t x = d->x + (((d->d1)&15)<<4);
11687 int32_t y = d->y + ((d->d1)&0xF0);
11688 rect(screen,x,y,x+15,y+15,vc(15));
11689 }
11690 break;
11691 }
11692
11693 return D_O_K;
11694 }
11695
11696 static DIALOG cflag_dlg[] =
11697 {
11698 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
11699 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11700 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11701 12 { jwin_abclist_proc, 72-12-4, 60+4, 176+24+8, 92+3, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11702 12 { jwin_button_proc, 70, 163, 51, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11703 12 { jwin_button_proc, 190, 163, 51, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11704 12 { jwin_button_proc, 130, 163, 51, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Help", NULL, NULL },
11705 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11706 };
11707
11708
11709 void questrev_help()
11710 {
11711 jwin_alert("Help","The revision number of your quest.",NULL,NULL,"O&K",NULL,'k',16,get_zc_font(font_lfont));
11712 }
11713
11714 void questminrev_help()
11715 {
11716 jwin_alert("Help","If a player's saved game was from a revision less than the minimum", "revision, they have to restart from the beginning.", "This is useful if you make major changes to your quest.","O&K",NULL,'k',16,get_zc_font(font_lfont));
11717 }
11718
11719 int32_t select_cflag(const char *prompt,int32_t flag)
11720 {
11721 cflag_dlg[0].dp=(void *)prompt;
11722 cflag_dlg[0].dp2=get_zc_font(font_lfont);
11723 GUI::ListData ld = GUI::ZCListData::mapflag(numericalFlags, true);
11724 ListData select_cflag_list = ld.getJWin(&font);
11725 int32_t index = ld.findIndex(flag);
11726 cflag_dlg[2].d1=index;
11727 cflag_dlg[2].dp=(void *) &select_cflag_list;
11728
11729 large_dialog(cflag_dlg);
11730
11731 int32_t ret;
11732
11733 do
11734 {
11735 ret=do_zqdialog(cflag_dlg,2);
11736
11737 if(ret==5)
11738 {
11739 cflag_help(ld.getValue(cflag_dlg[2].d1));
11740 }
11741 }
11742 while(ret==5);
11743
11744 if(ret==0||ret==4)
11745 {
11746 position_mouse_z(0);
11747 return -1;
11748 }
11749
11750 return ld.getValue(cflag_dlg[2].d1);
11751 }
11752
11753 int32_t select_flag(int32_t &f)
11754 {
11755 int32_t ret=select_cflag("Flag Type",f);
11756
11757 if(ret>=0)
11758 {
11759 f=ret;
11760 return true;
11761 }
11762
11763 return false;
11764 }
11765
11766 int32_t d_scombo_proc(int32_t msg,DIALOG *d,int32_t c)
11767 {
11768 //these are here to bypass compiler warnings about unused arguments
11769 c=c;
11770
11771 switch(msg)
11772 {
11773 case MSG_CLICK:
11774 {
11775 int32_t c2=d->d1;
11776 int32_t cs=d->fg;
11777 int32_t f=d->d2;
11778
11779 if(d->bg==1 || (CHECK_CTRL_CMD))
11780 {
11781 while(gui_mouse_b())
11782 {
11783 /* do nothing */
11784 rest(1);
11785 }
11786
11787 if(select_flag(f))
11788 {
11789 d->d2=f;
11790
11791 }
11792 }
11793 else if(key[KEY_LSHIFT])
11794 {
11795 if(gui_mouse_b()&1)
11796 {
11797 d->d1++;
11798
11799 if(d->d1>=MAXCOMBOS) d->d1=0;
11800 }
11801 else if(gui_mouse_b()&2)
11802 {
11803 d->d1--;
11804
11805 if(d->d1<0) d->d1=MAXCOMBOS-1;
11806 }
11807 }
11808 else if(key[KEY_RSHIFT])
11809 {
11810 if(gui_mouse_b()&1)
11811 {
11812 d->fg++;
11813
11814 if(d->fg>11) d->fg=0;
11815 }
11816 else if(gui_mouse_b()&2)
11817 {
11818 d->fg--;
11819
11820 if(d->fg<0) d->fg=11;
11821 }
11822 }
11823 else if(key[KEY_ALT])
11824 {
11825 if(gui_mouse_b()&1)
11826 {
11827 d->d1 = Combo;
11828 d->fg = CSet;
11829 }
11830 }
11831 else
11832 {
11833 if(select_combo_2(c2, cs))
11834 {
11835 d->d1=c2;
11836 d->fg=cs;
11837 }
11838 }
11839
11840 return D_REDRAW;
11841 }
11842 break;
11843
11844 case MSG_DRAW:
11845 d->w = 32;
11846 d->h = 32;
11847
11848 BITMAP *buf = create_bitmap_ex(8,16,16);
11849 BITMAP *bigbmp = create_bitmap_ex(8,d->w,d->h);
11850
11851 if(buf && bigbmp)
11852 {
11853 clear_bitmap(buf);
11854
11855 if(d->bg) //flags only
11856 {
11857 put_flag(buf,0,0,d->d2);
11858 }
11859 else if(d->d1)
11860 {
11861 putcombo(buf,0,0,d->d1,d->fg);
11862
11863 if(Flags&cFLAGS)
11864 put_flags(buf,0,0,d->d1,d->fg,cFLAGS,d->d2);
11865 }
11866
11867 stretch_blit(buf, bigbmp, 0,0, 16, 16, 0, 0, d->w, d->h);
11868 destroy_bitmap(buf);
11869 blit(bigbmp,screen,0,0,d->x-1,d->y-1,d->w,d->h);
11870 destroy_bitmap(bigbmp);
11871 }
11872
11873
11874 /*BITMAP *buf = create_bitmap_ex(8,16,16);
11875 if(buf)
11876 {
11877 clear_bitmap(buf);
11878 if(d->d1)
11879 putcombo(buf,0,0,d->d1,d->fg);
11880
11881 blit(buf,screen,0,0,d->x,d->y,d->w,d->h);
11882 destroy_bitmap(buf);
11883 }*/
11884 break;
11885 }
11886
11887 return D_O_K;
11888 }
11889
11890 /*int32_t d_scombo2_proc(int32_t msg, DIALOG *d, int32_t c)
11891 {
11892 //these are here to bypass compiler warnings about unused arguments
11893 c=c;
11894
11895 switch(msg)
11896 {
11897 case MSG_CLICK:
11898 if (CHECK_CTRL_CMD)
11899 {
11900 select_scombo(d->d1);
11901 }
11902 else
11903 {
11904 select_scombo(d->d1);
11905 }
11906 d_scombo_proc(MSG_DRAW,d,0);
11907 break;
11908
11909
11910 case MSG_DRAW:
11911 BITMAP *buf = create_bitmap_ex(8,16,16);
11912 if(buf)
11913 {
11914 clear_bitmap(buf);
11915 Map.draw_secret2(buf,d->d1);
11916 blit(buf,screen,0,0,d->x,d->y,16,16);
11917 destroy_bitmap(buf);
11918 }
11919 break;
11920 }
11921
11922 return D_O_K;
11923 }*/
11924
11925 int32_t onSecretF();
11926
11927 static int32_t secret_burn_list[] =
11928 {
11929 // dialog control number
11930 4, 5, 6, 7, 48, 49, 50, 51, 92, 93, 94, 95, -1
11931 };
11932
11933 static int32_t secret_arrow_list[] =
11934 {
11935 // dialog control number
11936 8, 9, 10, 52, 53, 54, 96, 97, 98, -1
11937 };
11938
11939 static int32_t secret_bomb_list[] =
11940 {
11941 // dialog control number
11942 11, 12, 55, 56, 99, 100, -1
11943 };
11944
11945 static int32_t secret_boomerang_list[] =
11946 {
11947 // dialog control number
11948 13, 14, 15, 57, 58, 59, 101, 102, 103, -1
11949 };
11950
11951 static int32_t secret_magic_list[] =
11952 {
11953 // dialog control number
11954 16, 17, 60, 61, 104, 105, -1
11955 };
11956
11957 static int32_t secret_sword_list[] =
11958 {
11959 // dialog control number
11960 18, 19, 20, 21, 22, 23, 24, 25, 62, 63, 64, 65, 66, 67, 68, 69, 106, 107, 108, 109, 110, 111, 112, 113, -1
11961 };
11962
11963 static int32_t secret_misc_list[] =
11964 {
11965 // dialog control number
11966 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, -1
11967 };
11968
11969 static TABPANEL secret_tabs[] =
11970 {
11971 // (text)
11972 { (char *)"Burn", D_SELECTED, secret_burn_list, 0, NULL },
11973 { (char *)"Arrow", 0, secret_arrow_list, 0, NULL },
11974 { (char *)"Bomb", 0, secret_bomb_list, 0, NULL },
11975 { (char *)"Boomerang", 0, secret_boomerang_list, 0, NULL },
11976 { (char *)"Magic", 0, secret_magic_list, 0, NULL },
11977 { (char *)"Sword", 0, secret_sword_list, 0, NULL },
11978 { (char *)"Misc", 0, secret_misc_list, 0, NULL },
11979 { NULL, 0, NULL, 0, NULL }
11980 };
11981
11982 static DIALOG secret_dlg[] =
11983 {
11984 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
11985 { jwin_win_proc, 0, 0, 301, 212, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11986 { jwin_tab_proc, 6, 25, 289, 156, 0, 0, 0, 0, 0, 0, (void *) secret_tabs, NULL, (void *)secret_dlg },
11987 { jwin_button_proc, 80, 187, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11988 { jwin_button_proc, 160, 187, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11989 // 4
11990 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Any Fire", NULL, NULL },
11991 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Strong Fire", NULL, NULL },
11992 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Fire", NULL, NULL },
11993 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Divine Fire", NULL, NULL },
11994 //8
11995 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wooden Arrow", NULL, NULL },
11996 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Silver Arrow", NULL, NULL },
11997 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Golden Arrow", NULL, NULL },
11998 //11
11999 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Bomb", NULL, NULL },
12000 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Super Bomb", NULL, NULL },
12001 //13
12002 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wooden Boomerang", NULL, NULL },
12003 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Boomerang", NULL, NULL },
12004 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Fire Boomerang", NULL, NULL },
12005 //16
12006 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wand Magic", NULL, NULL },
12007 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Reflected Magic", NULL, NULL },
12008 //18
12009 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Sword", NULL, NULL },
12010 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "White Sword", NULL, NULL },
12011 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Sword", NULL, NULL },
12012 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Master Sword", NULL, NULL },
12013 { jwin_text_proc, 160, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Sword Beam", NULL, NULL },
12014 { jwin_text_proc, 160, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "White Sword Beam", NULL, NULL },
12015 { jwin_text_proc, 160, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Sword Beam", NULL, NULL },
12016 { jwin_text_proc, 160, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Master Sword Beam", NULL, NULL },
12017 //26
12018 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Stairs", NULL, NULL },
12019 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Reflected Fireball", NULL, NULL },
12020 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hookshot", NULL, NULL },
12021 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wand", NULL, NULL },
12022 { jwin_text_proc, 12, 141, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hammer", NULL, NULL },
12023 { jwin_text_proc, 12, 163, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Any Weapon", NULL, NULL },
12024 //32
12025 { jwin_ctext_proc, 235, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Flags 16-31", NULL, NULL },
12026 { jwin_text_proc, 87, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Secrets->Next (Flag only)", NULL, NULL },
12027 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 03", NULL, NULL },
12028 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 04", NULL, NULL },
12029 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 05", NULL, NULL },
12030 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 06", NULL, NULL },
12031 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 07", NULL, NULL },
12032 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 08", NULL, NULL },
12033 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 09", NULL, NULL },
12034 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 10", NULL, NULL },
12035 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 11", NULL, NULL },
12036 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 12", NULL, NULL },
12037 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 13", NULL, NULL },
12038 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 14", NULL, NULL },
12039 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 15", NULL, NULL },
12040 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 16", NULL, NULL },
12041 //48 (burn)
12042 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12043 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12044 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12045 { jwin_frame_proc, 108, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12046 //52 (arrow)
12047 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12048 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12049 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12050 //55 (bomb)
12051 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12052 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12053 //57 (boomerang)
12054 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12055 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12056 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12057 //60 (magic)
12058 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12059 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12060 //62 (sword)
12061 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12062 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12063 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12064 { jwin_frame_proc, 108, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12065 { jwin_frame_proc, 256, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12066 { jwin_frame_proc, 256, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12067 { jwin_frame_proc, 256, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12068 { jwin_frame_proc, 256, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12069 //70 (misc)
12070 { jwin_frame_proc, 63, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12071 { jwin_frame_proc, 63, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12072 { jwin_frame_proc, 63, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12073 { jwin_frame_proc, 63, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12074 { jwin_frame_proc, 63, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12075 { jwin_frame_proc, 63, 157, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12076 //76 (16-32)
12077 { jwin_frame_proc, 192, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12078 { jwin_frame_proc, 214, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12079 { jwin_frame_proc, 236, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12080 { jwin_frame_proc, 258, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12081 { jwin_frame_proc, 192, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12082 { jwin_frame_proc, 214, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12083 { jwin_frame_proc, 236, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12084 { jwin_frame_proc, 258, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12085 { jwin_frame_proc, 192, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12086 { jwin_frame_proc, 214, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12087 { jwin_frame_proc, 236, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12088 { jwin_frame_proc, 258, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12089 { jwin_frame_proc, 192, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12090 { jwin_frame_proc, 214, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12091 { jwin_frame_proc, 236, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12092 { jwin_frame_proc, 258, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12093
12094 //92 (burn)
12095 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12096 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12097 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12098 { d_scombo_proc, 110, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12099 //96 (arrow)
12100 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12101 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12102 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12103 //99 (bomb)
12104 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12105 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12106 //101 (boomerang)
12107 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12108 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12109 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12110 //104 (magic)
12111 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12112 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12113 //106 (sword)
12114 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12115 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12116 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12117 { d_scombo_proc, 110, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12118 { d_scombo_proc, 258, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12119 { d_scombo_proc, 258, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12120 { d_scombo_proc, 258, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12121 { d_scombo_proc, 258, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12122 //114 (misc)
12123 { d_scombo_proc, 65, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12124 { d_scombo_proc, 65, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12125 { d_scombo_proc, 65, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12126 { d_scombo_proc, 65, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12127 { d_scombo_proc, 65, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12128 { d_scombo_proc, 65, 159, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12129 //120 (16-32)
12130 { d_scombo_proc, 194, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12131 { d_scombo_proc, 216, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12132 { d_scombo_proc, 238, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12133 { d_scombo_proc, 260, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12134 { d_scombo_proc, 194, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12135 { d_scombo_proc, 216, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12136 { d_scombo_proc, 238, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12137 { d_scombo_proc, 260, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12138 { d_scombo_proc, 194, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12139 { d_scombo_proc, 216, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12140 { d_scombo_proc, 238, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12141 { d_scombo_proc, 260, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12142 { d_scombo_proc, 194, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12143 { d_scombo_proc, 216, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12144 { d_scombo_proc, 238, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12145 { d_scombo_proc, 260, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12146 //136 Secrets->Next
12147 { jwin_frame_proc, 158, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12148 { d_scombo_proc, 160, 49, 16, 16, 0, 1, 0, 0, 0, 0, NULL, NULL, NULL },
12149 //138
12150 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
12151 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 'f', 0, 0, 0, (void *) onSecretF, NULL, NULL },
12152 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12153 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12154 };
12155
12156 int32_t onSecretF()
12157 {
12158 Flags^=cFLAGS;
12159 object_message(secret_dlg+1, MSG_DRAW, 0);
12160 return D_O_K;
12161 }
12162
12163
12164 int32_t onSecretCombo()
12165 {
12166 secret_dlg[0].dp2=get_zc_font(font_lfont);
12167
12168
12169 mapscr *s;
12170
12171 if(CurrentLayer==0)
12172 {
12173 s=Map.CurrScr();
12174 }
12175 else
12176 {
12177 // s=TheMaps[(Map.CurrScr()->layermap[CurrentLayer-1]-1)*MAPSCRS+(Map.CurrScr()->layerscreen[CurrentLayer-1])];
12178 s=Map.AbsoluteScr((Map.CurrScr()->layermap[CurrentLayer-1]-1), (Map.CurrScr()->layerscreen[CurrentLayer-1]));
12179 }
12180 if(!s) return D_O_K;
12181
12182 char secretcombonumstr[27];
12183 sprintf(secretcombonumstr,"Secret Combos for Layer %d", CurrentLayer);
12184 secret_dlg[0].dp = secretcombonumstr;
12185
12186 secret_dlg[92].d1 = s->secretcombo[sBCANDLE];
12187 secret_dlg[92].fg = s->secretcset[sBCANDLE];
12188 secret_dlg[92].d2 = s->secretflag[sBCANDLE];
12189
12190 secret_dlg[93].d1 = s->secretcombo[sRCANDLE];
12191 secret_dlg[93].fg = s->secretcset[sRCANDLE];
12192 secret_dlg[93].d2 = s->secretflag[sRCANDLE];
12193
12194 secret_dlg[94].d1 = s->secretcombo[sWANDFIRE];
12195 secret_dlg[94].fg = s->secretcset[sWANDFIRE];
12196 secret_dlg[94].d2 = s->secretflag[sWANDFIRE];
12197
12198 secret_dlg[95].d1 = s->secretcombo[sDIVINEFIRE];
12199 secret_dlg[95].fg = s->secretcset[sDIVINEFIRE];
12200 secret_dlg[95].d2 = s->secretflag[sDIVINEFIRE];
12201
12202 secret_dlg[96].d1 = s->secretcombo[sARROW];
12203 secret_dlg[96].fg = s->secretcset[sARROW];
12204 secret_dlg[96].d2 = s->secretflag[sARROW];
12205
12206 secret_dlg[97].d1 = s->secretcombo[sSARROW];
12207 secret_dlg[97].fg = s->secretcset[sSARROW];
12208 secret_dlg[97].d2 = s->secretflag[sSARROW];
12209
12210 secret_dlg[98].d1 = s->secretcombo[sGARROW];
12211 secret_dlg[98].fg = s->secretcset[sGARROW];
12212 secret_dlg[98].d2 = s->secretflag[sGARROW];
12213
12214 secret_dlg[99].d1 = s->secretcombo[sBOMB];
12215 secret_dlg[99].fg = s->secretcset[sBOMB];
12216 secret_dlg[99].d2 = s->secretflag[sBOMB];
12217
12218 secret_dlg[100].d1 = s->secretcombo[sSBOMB];
12219 secret_dlg[100].fg = s->secretcset[sSBOMB];
12220 secret_dlg[100].d2 = s->secretflag[sSBOMB];
12221
12222 for(int32_t i=0; i<3; i++)
12223 {
12224 secret_dlg[101+i].d1 = s->secretcombo[sBRANG+i];
12225 secret_dlg[101+i].fg = s->secretcset[sBRANG+i];
12226 secret_dlg[101+i].d2 = s->secretflag[sBRANG+i];
12227 }
12228
12229 for(int32_t i=0; i<2; i++)
12230 {
12231 secret_dlg[104+i].d1 = s->secretcombo[sWANDMAGIC+i];
12232 secret_dlg[104+i].fg = s->secretcset[sWANDMAGIC+i];
12233 secret_dlg[104+i].d2 = s->secretflag[sWANDMAGIC+i];
12234 }
12235
12236 for(int32_t i=0; i<8; i++)
12237 {
12238 secret_dlg[106+i].d1 = s->secretcombo[sSWORD+i];
12239 secret_dlg[106+i].fg = s->secretcset[sSWORD+i];
12240 secret_dlg[106+i].d2 = s->secretflag[sSWORD+i];
12241 }
12242
12243 secret_dlg[114].d1 = s->secretcombo[sSTAIRS];
12244 secret_dlg[114].fg = s->secretcset[sSTAIRS];
12245 secret_dlg[114].d2 = s->secretflag[sSTAIRS];
12246
12247 secret_dlg[115].d1 = s->secretcombo[sREFFIREBALL];
12248 secret_dlg[115].fg = s->secretcset[sREFFIREBALL];
12249 secret_dlg[115].d2 = s->secretflag[sREFFIREBALL];
12250
12251 for(int32_t i=0; i<4; i++)
12252 {
12253 secret_dlg[116+i].d1 = s->secretcombo[sHOOKSHOT+i];
12254 secret_dlg[116+i].fg = s->secretcset[sHOOKSHOT+i];
12255 secret_dlg[116+i].d2 = s->secretflag[sHOOKSHOT+i];
12256 }
12257
12258 for(int32_t i=0; i<16; i++)
12259 {
12260 secret_dlg[120+i].d1 = s->secretcombo[sSECRET01+i];
12261 secret_dlg[120+i].fg = s->secretcset[sSECRET01+i];
12262 secret_dlg[120+i].d2 = s->secretflag[sSECRET01+i];
12263 }
12264
12265 //Sec->Next doesn't have a combo/cset value associated
12266 secret_dlg[137].d1 = 0;
12267 secret_dlg[137].fg = 0;
12268 secret_dlg[137].d2 = s->secretflag[sSECNEXT];
12269
12270 large_dialog(secret_dlg,1.75);
12271
12272 for(int32_t q = 0; secret_dlg[q].proc != NULL; ++q)
12273 {
12274 if(secret_dlg[q].proc == jwin_frame_proc)
12275 secret_dlg[q].w = secret_dlg[q].h = 36;
12276 }
12277
12278 go();
12279
12280 if(do_zqdialog(secret_dlg,3) == 2)
12281 {
12282 saved = false;
12283 s->secretcombo[sBCANDLE] = secret_dlg[92].d1;
12284 s->secretcset[sBCANDLE] = secret_dlg[92].fg;
12285 s->secretflag[sBCANDLE] = secret_dlg[92].d2;
12286
12287 s->secretcombo[sRCANDLE] = secret_dlg[93].d1;
12288 s->secretcset[sRCANDLE] = secret_dlg[93].fg;
12289 s->secretflag[sRCANDLE] = secret_dlg[93].d2;
12290
12291 s->secretcombo[sWANDFIRE] = secret_dlg[94].d1;
12292 s->secretcset[sWANDFIRE] = secret_dlg[94].fg;
12293 s->secretflag[sWANDFIRE] = secret_dlg[94].d2;
12294
12295 s->secretcombo[sDIVINEFIRE] = secret_dlg[95].d1;
12296 s->secretcset[sDIVINEFIRE] = secret_dlg[95].fg;
12297 s->secretflag[sDIVINEFIRE] = secret_dlg[95].d2;
12298
12299 s->secretcombo[sARROW] = secret_dlg[96].d1;
12300 s->secretcset[sARROW] = secret_dlg[96].fg;
12301 s->secretflag[sARROW] = secret_dlg[96].d2;
12302
12303 s->secretcombo[sSARROW] = secret_dlg[97].d1;
12304 s->secretcset[sSARROW] = secret_dlg[97].fg;
12305 s->secretflag[sSARROW] = secret_dlg[97].d2;
12306
12307 s->secretcombo[sGARROW] = secret_dlg[98].d1;
12308 s->secretcset[sGARROW] = secret_dlg[98].fg;
12309 s->secretflag[sGARROW] = secret_dlg[98].d2;
12310
12311 s->secretcombo[sBOMB] = secret_dlg[99].d1;
12312 s->secretcset[sBOMB] = secret_dlg[99].fg;
12313 s->secretflag[sBOMB] = secret_dlg[99].d2;
12314
12315 s->secretcombo[sSBOMB] = secret_dlg[100].d1;
12316 s->secretcset[sSBOMB] = secret_dlg[100].fg;
12317 s->secretflag[sSBOMB] = secret_dlg[100].d2;
12318
12319 for(int32_t i=0; i<3; i++)
12320 {
12321 s->secretcombo[sBRANG+i] = secret_dlg[101+i].d1;
12322 s->secretcset[sBRANG+i] = secret_dlg[101+i].fg;
12323 s->secretflag[sBRANG+i] = secret_dlg[101+i].d2;
12324 }
12325
12326 for(int32_t i=0; i<2; i++)
12327 {
12328 s->secretcombo[sWANDMAGIC+i] = secret_dlg[104+i].d1;
12329 s->secretcset[sWANDMAGIC+i] = secret_dlg[104+i].fg;
12330 s->secretflag[sWANDMAGIC+i] = secret_dlg[104+i].d2;
12331 }
12332
12333 for(int32_t i=0; i<8; i++)
12334 {
12335 s->secretcombo[sSWORD+i] = secret_dlg[106+i].d1;
12336 s->secretcset[sSWORD+i] = secret_dlg[106+i].fg;
12337 s->secretflag[sSWORD+i] = secret_dlg[106+i].d2;
12338 }
12339
12340 s->secretcombo[sSTAIRS] = secret_dlg[114].d1;
12341 s->secretcset[sSTAIRS] = secret_dlg[114].fg;
12342 s->secretflag[sSTAIRS] = secret_dlg[114].d2;
12343
12344 s->secretcombo[sREFFIREBALL] = secret_dlg[115].d1;
12345 s->secretcset[sREFFIREBALL] = secret_dlg[115].fg;
12346 s->secretflag[sREFFIREBALL] = secret_dlg[115].d2;
12347
12348 for(int32_t i=0; i<4; i++)
12349 {
12350 s->secretcombo[sHOOKSHOT+i] = secret_dlg[116+i].d1;
12351 s->secretcset[sHOOKSHOT+i] = secret_dlg[116+i].fg;
12352 s->secretflag[sHOOKSHOT+i] = secret_dlg[116+i].d2;
12353 }
12354
12355 for(int32_t i=0; i<16; i++)
12356 {
12357 s->secretcombo[sSECRET01+i] = secret_dlg[120+i].d1;
12358 s->secretcset[sSECRET01+i] = secret_dlg[120+i].fg;
12359 s->secretflag[sSECRET01+i] = secret_dlg[120+i].d2;
12360 }
12361 s->secretflag[sSECNEXT] = secret_dlg[137].d2;
12362
12363 }
12364
12365 comeback();
12366 return D_O_K;
12367 }
12368
12369 static DIALOG under_dlg[] =
12370 {
12371 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
12372 { jwin_win_proc, 72, 60, 176+1,120+1,vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12373 { jwin_text_proc, 115, 83, 20, 20, vc(14), vc(1), 0, 0, 0, 0, (void *) "Current", NULL, NULL },
12374 { d_comboframe_proc, 122, 92, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12375 { d_combo_proc, 124, 94, 16, 16, 0, 0, 0, D_NOCLICK, 0, 0, NULL, NULL, NULL },
12376 { jwin_text_proc, 184, 83, 20, 20, vc(14), vc(1), 0, 0, 0, 0, (void *) "New", NULL, NULL },
12377 { d_comboframe_proc, 182, 92, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12378 { d_combo_proc, 184, 94, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12379 { jwin_button_proc, 90, 124, 61, 21, vc(14), vc(1), 's', D_EXIT, 0, 0, (void *) "&Set", NULL, NULL },
12380 { jwin_button_proc, 170, 124, 61, 21, vc(14), vc(1), 'c', D_EXIT, 0, 0, (void *) "&Cancel", NULL, NULL },
12381 { jwin_button_proc, 90, 152, 61, 21, vc(14), vc(1), 'a', D_EXIT, 0, 0, (void *) "Set &All", NULL, NULL },
12382 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
12383 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12384 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12385 };
12386
12387 int32_t onUnderCombo()
12388 {
12389 char titlebuf[64];
12390 sprintf(titlebuf, "Under Combo (Layer %d)", CurrentLayer);
12391 under_dlg[0].dp = titlebuf;
12392 under_dlg[0].dp2 = get_zc_font(font_lfont);
12393 mapscr* scr;
12394 if(CurrentLayer==0)
12395 {
12396 scr=Map.CurrScr();
12397 }
12398 else
12399 {
12400 auto map=Map.CurrScr()->layermap[CurrentLayer-1]-1;
12401 auto screen=Map.CurrScr()->layerscreen[CurrentLayer-1];
12402 scr = Map.AbsoluteScr(map,screen);
12403 }
12404 if(!scr) return D_O_K;
12405
12406 under_dlg[3].d1=scr->undercombo;
12407 under_dlg[3].fg=scr->undercset;
12408
12409 under_dlg[6].d1=Combo;
12410 under_dlg[6].fg=CSet;
12411
12412 large_dialog(under_dlg);
12413 // Doesn't place "New" and "Current" text too well
12414 under_dlg[1].x=342;
12415 under_dlg[4].x=438;
12416
12417 int32_t ret = do_zqdialog(under_dlg,-1);
12418
12419 if(ret==7)
12420 {
12421 saved=false;
12422 scr->undercombo = under_dlg[6].d1;
12423 scr->undercset = under_dlg[6].fg;
12424 }
12425
12426 if(ret==9 && jwin_alert("Confirm Overwrite","Set all Under Combos","on this map?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
12427 {
12428 saved=false;
12429
12430 for(int32_t i=0; i<128; i++)
12431 {
12432 Map.Scr(i)->undercombo = under_dlg[6].d1;
12433 Map.Scr(i)->undercset = under_dlg[6].fg;
12434 }
12435 }
12436
12437 return D_O_K;
12438 }
12439
12440 static DIALOG list_dlg[] =
12441 {
12442 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
12443 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12444 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12445 12 { jwin_list_proc, 72-12-4, 60+4, 176+24+8, 92+3, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12446 12 { jwin_button_proc, 90, 163, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
12447 12 { jwin_button_proc, 170, 163, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
12448 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12449 };
12450
12451 /*
12452 typedef struct item_struct {
12453 char *s;
12454 int32_t i;
12455 } item_struct;
12456 */
12457 item_struct bii[MAXITEMS+1];
12458 int32_t bii_cnt=-1;
12459
12460 void build_bii_list(bool usenone)
12461 {
12462 int32_t start=bii_cnt=0;
12463
12464 if(usenone)
12465 {
12466 bii[0].s = (char *)"(None)";
12467 bii[0].i = -2;
12468 bii_cnt=start=1;
12469 }
12470
12471 for(int32_t i=0; i<MAXITEMS; i++)
12472 {
12473 bii[bii_cnt].s = item_string[i];
12474 bii[bii_cnt].i = i;
12475 ++bii_cnt;
12476 }
12477
12478 for(int32_t i=start; i<bii_cnt-1; i++)
12479 {
12480 for(int32_t j=i+1; j<bii_cnt; j++)
12481 {
12482 if(stricmp(bii[i].s,bii[j].s)>0 && strcmp(bii[j].s,""))
12483 {
12484 zc_swap(bii[i],bii[j]);
12485 }
12486 }
12487 }
12488 }
12489
12490
12491 const char *itemlist(int32_t index, int32_t *list_size)
12492 {
12493 if(index<0)
12494 {
12495 *list_size = bii_cnt;
12496 return NULL;
12497 }
12498
12499 return bii[index].s;
12500 }
12501 const char *itemlist_num(int32_t index, int32_t *list_size)
12502 {
12503 if(index<0)
12504 {
12505 *list_size = bii_cnt;
12506 return NULL;
12507 }
12508 static char biin_buf[64+6];
12509 if(bii[index].i < 0)
12510 return bii[index].s;
12511 sprintf(biin_buf, "%s (%03d)", bii[index].s, bii[index].i);
12512 return biin_buf;
12513 }
12514
12515 // disable items on dmaps stuff
12516 int32_t DI[MAXITEMS];
12517 int32_t nDI;
12518
12519 void initDI(int32_t index)
12520 {
12521 int32_t j=0;
12522
12523 for(int32_t i=0; i<MAXITEMS; i++)
12524 {
12525 int32_t index1=bii[i].i; // true index of item in dmap's DI list
12526
12527 if(DMaps[index].disableditems[index1])
12528 {
12529 DI[j]=i;
12530 j++;
12531 }
12532 }
12533
12534 nDI=j;
12535
12536 for(int32_t i=j; i<MAXITEMS; i++) DI[j]=0;
12537
12538 return;
12539 }
12540
12541 void insertDI(int32_t id, int32_t index)
12542 {
12543 int32_t trueid=bii[id].i;
12544 DMaps[index].disableditems[trueid] |= 1; //bit set
12545 initDI(index);
12546 return;
12547 }
12548
12549 void deleteDI(int32_t id, int32_t index)
12550 {
12551 int32_t i=DI[id];
12552 int32_t trueid=bii[i].i;
12553 DMaps[index].disableditems[trueid] &= (~1); // bit clear
12554 initDI(index);
12555 return;
12556 }
12557
12558 const char *DIlist(int32_t index, int32_t *list_size)
12559 {
12560 if(index<0)
12561 {
12562 *list_size = nDI;
12563 return NULL;
12564 }
12565
12566 int32_t i=DI[index];
12567 return bii[i].s;
12568
12569 }
12570
12571 weapon_struct biw[MAXWPNS];
12572 int32_t biw_cnt=-1;
12573
12574 void build_biw_list()
12575 {
12576 int32_t start=biw_cnt=0;
12577
12578 for(int32_t i=start; i<MAXWPNS; i++)
12579 {
12580 biw[biw_cnt].s = (char *)weapon_string[i];
12581 biw[biw_cnt].i = i;
12582 ++biw_cnt;
12583 }
12584
12585 for(int32_t i=start; i<biw_cnt-1; i++)
12586 {
12587 for(int32_t j=i+1; j<biw_cnt; j++)
12588 if(stricmp(biw[i].s,biw[j].s)>0 && strcmp(biw[j].s,""))
12589 zc_swap(biw[i],biw[j]);
12590 }
12591 }
12592
12593 const char *weaponlist(int32_t index, int32_t *list_size)
12594 {
12595 if(index<0)
12596 {
12597 *list_size = biw_cnt;
12598 return NULL;
12599 }
12600
12601 return biw[index].s;
12602 }
12603 const char *weaponlist_num(int32_t index, int32_t *list_size)
12604 {
12605 if(index<0)
12606 {
12607 *list_size = biw_cnt;
12608 return NULL;
12609 }
12610 static char biwn_buf[64+6];
12611 if(biw[index].i < 0)
12612 return biw[index].s;
12613 sprintf(biwn_buf, "%s (%03d)", biw[index].s, biw[index].i);
12614 return biwn_buf;
12615 }
12616 int32_t writeoneweapon(PACKFILE *f, int32_t index)
12617 {
12618 dword section_version=V_WEAPONS;
12619 int32_t zversion = ZELDA_VERSION;
12620 int32_t zbuild = VERSION_BUILD;
12621 int32_t iid = biw[index].i;
12622 al_trace("Writing Weapon Sprite .zwpnspr file for weapon id: %d\n", iid);
12623
12624 //section version info
12625 if(!p_iputl(zversion,f))
12626 {
12627 return 0;
12628 }
12629 if(!p_iputl(zbuild,f))
12630 {
12631 return 0;
12632 }
12633 if(!p_iputw(section_version,f))
12634 {
12635 return 0;
12636 }
12637
12638 if(!write_deprecated_section_cversion(section_version, f))
12639 {
12640 return 0;
12641 }
12642
12643 //weapon string
12644
12645 if(!pfwrite((char *)weapon_string[iid], 64, f))
12646 {
12647 return 0;
12648 }
12649
12650 if(!p_putc(wpnsbuf[iid].misc,f))
12651 {
12652 return 0;
12653 }
12654
12655 if(!p_putc(wpnsbuf[iid].csets,f))
12656 {
12657 return 0;
12658 }
12659
12660 if(!p_putc(wpnsbuf[iid].frames,f))
12661 {
12662 return 0;
12663 }
12664
12665 if(!p_putc(wpnsbuf[iid].speed,f))
12666 {
12667 return 0;
12668 }
12669
12670 if(!p_putc(wpnsbuf[iid].type,f))
12671 {
12672 return 0;
12673 }
12674
12675 if(!p_iputw(wpnsbuf[iid].script,f))
12676 {
12677 return 0;
12678 }
12679
12680 //2.55 starts here
12681 if(!p_iputl(wpnsbuf[iid].tile,f))
12682 {
12683 return 0;
12684 }
12685
12686 return 1;
12687 }
12688
12689
12690 int32_t readoneweapon(PACKFILE *f, int32_t index)
12691 {
12692 dword section_version = 0;
12693 int32_t zversion = 0;
12694 int32_t zbuild = 0;
12695 wpndata tempwpnspr;
12696 memset(&tempwpnspr, 0, sizeof(wpndata));
12697
12698
12699 //char dmapstring[64]={0};
12700 //section version info
12701 if(!p_igetl(&zversion,f))
12702 {
12703 return 0;
12704 }
12705 if(!p_igetl(&zbuild,f))
12706 {
12707 return 0;
12708 }
12709 if(!p_igetw(&section_version,f))
12710 {
12711 return 0;
12712 }
12713 if(!read_deprecated_section_cversion(f))
12714 {
12715 return 0;
12716 }
12717 al_trace("readoneweapon section_version: %d\n", section_version);
12718
12719 if ( zversion > ZELDA_VERSION )
12720 {
12721 al_trace("Cannot read .zwpnspr packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
12722 return 0;
12723 }
12724
12725 else if ( ( section_version > V_WEAPONS ) )
12726 {
12727 al_trace("Cannot read .zwpnspr packfile made using V_WEAPONS (%d)\n", section_version);
12728 return 0;
12729
12730 }
12731 else
12732 {
12733 al_trace("Reading a .zwpnspr packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
12734 }
12735
12736 char tmp_wpn_name[64];
12737 memset(tmp_wpn_name,0,64);
12738 if(!pfread(&tmp_wpn_name, 64, f))
12739 {
12740 return 0;
12741 }
12742
12743 word oldtile = 0;
12744 if(section_version < 8)
12745 if(!p_igetw(&oldtile,f))
12746 return 0;
12747
12748 if(!p_getc(&tempwpnspr.misc,f))
12749 {
12750 return 0;
12751 }
12752
12753 if(!p_getc(&tempwpnspr.csets,f))
12754 {
12755 return 0;
12756 }
12757
12758 if(!p_getc(&tempwpnspr.frames,f))
12759 {
12760 return 0;
12761 }
12762
12763 if(!p_getc(&tempwpnspr.speed,f))
12764 {
12765 return 0;
12766 }
12767
12768 if(!p_getc(&tempwpnspr.type,f))
12769 {
12770 return 0;
12771 }
12772
12773 if(!p_igetw(&tempwpnspr.script,f))
12774 {
12775 return 0;
12776 }
12777
12778 //2.55 starts here
12779 if ( zversion >= 0x255 )
12780 {
12781 if ( section_version >= 7 )
12782 {
12783 if(!p_igetl(&tempwpnspr.tile,f))
12784 {
12785 return 0;
12786 }
12787 }
12788 }
12789 if ( zversion < 0x255 )
12790 {
12791 tempwpnspr.tile = oldtile;
12792 }
12793 ::memcpy( &(wpnsbuf[biw[index].i]),&tempwpnspr, sizeof(wpndata));
12794 ::memcpy(weapon_string[biw[index].i], tmp_wpn_name, 64);
12795
12796 return 1;
12797 }
12798
12799 static int32_t seldata_copy;
12800 static void (*seldata_paste_func)(int32_t, int32_t);
12801
12802 void seldata_rclick_func(int32_t index, int32_t x, int32_t y)
12803 {
12804 NewMenu rcmenu {
12805 { "&Copy", [&](){seldata_copy = index;} },
12806 { "Paste", "&v", [&]()
12807 {
12808 seldata_paste_func(seldata_copy, index);
12809 saved = false;
12810 }, 0, seldata_copy < 0 },
12811 };
12812 rcmenu.pop(x, y);
12813 }
12814
12815 int32_t select_data(const char *prompt,int32_t index,const char *(proc)(int32_t,int32_t*), FONT *title_font, void (*copyFunc)(int32_t, int32_t))
12816 {
12817 if(proc==NULL)
12818 return -1;
12819
12820 list_dlg[0].dp=(void *)prompt;
12821 list_dlg[0].dp2=title_font;
12822 list_dlg[2].d1=index;
12823 ListData select_list(proc, &font);
12824 list_dlg[2].dp=(void *) &select_list;
12825
12826 large_dialog(list_dlg);
12827
12828 seldata_copy=-1;
12829 seldata_paste_func=copyFunc;
12830 if(copyFunc)
12831 {
12832 list_dlg[2].flags|=D_USER<<1;
12833 list_dlg[2].dp3=(void*)seldata_rclick_func;
12834 }
12835 else
12836 {
12837 list_dlg[2].flags&=~(D_USER<<1);
12838 list_dlg[2].dp3=0;
12839 }
12840
12841 int32_t ret=do_zqdialog(list_dlg,2);
12842
12843 if(ret==0||ret==4)
12844 {
12845 position_mouse_z(0);
12846 return -1;
12847 }
12848
12849 return list_dlg[2].d1;
12850 }
12851
12852 int32_t select_data(const char *prompt,int32_t index,const char *(proc)(int32_t,int32_t*), const char *b1, const char *b2, FONT *title_font, void (*copyFunc)(int32_t, int32_t))
12853 {
12854 if(proc==NULL)
12855 return -1;
12856
12857 list_dlg[0].dp=(void *)prompt;
12858 list_dlg[0].dp2=title_font;
12859 list_dlg[2].d1=index;
12860 ListData select_data_list(proc, &font);
12861 list_dlg[2].dp=(void *) &select_data_list;
12862 list_dlg[3].dp=(void *)b1;
12863 list_dlg[4].dp=(void *)b2;
12864
12865 large_dialog(list_dlg);
12866
12867 seldata_copy=-1;
12868 seldata_paste_func=copyFunc;
12869 if(copyFunc)
12870 {
12871 list_dlg[2].flags|=D_USER<<1;
12872 list_dlg[2].dp3=(void*)seldata_rclick_func;
12873 }
12874 else
12875 {
12876 list_dlg[2].flags&=~(D_USER<<1);
12877 list_dlg[2].dp3=0;
12878 }
12879
12880 int32_t ret = do_zqdialog(list_dlg,2);
12881 list_dlg[3].dp=(void *) "OK";
12882 list_dlg[4].dp=(void *) "Cancel";
12883
12884 if(ret==0||ret==4)
12885 {
12886 position_mouse_z(0);
12887 return -1;
12888 }
12889
12890 position_mouse_z(0);
12891 return list_dlg[2].d1;
12892 }
12893
12894 static char sfx_str_buf[42];
12895
12896 const char *sfxlist(int32_t index, int32_t *list_size)
12897 {
12898 if(index>=0)
12899 {
12900 bound(index,0,WAV_COUNT-1);
12901 sprintf(sfx_str_buf,"%d: %s",index, index ? sfx_string[index] : "(None)");
12902 return sfx_str_buf;
12903 }
12904
12905 *list_size=WAV_COUNT;
12906 return NULL;
12907 }
12908
12909 12 static ListData sfx_list(sfxlist, &font);
12910
12911 const char *screenscriptdroplist(int32_t index, int32_t *list_size)
12912 {
12913 if(index<0)
12914 {
12915 *list_size = biscreens_cnt;
12916 return NULL;
12917 }
12918
12919 return biscreens[index].first.c_str();
12920 }
12921
12922 //droplist like the dialog proc, naming scheme for this stuff is awful...
12923 12 static ListData screenscript_list(screenscriptdroplist, &a4fonts[font_pfont]);
12924
12925 int32_t onScreenScript()
12926 {
12927 call_screendata_dialog(7);
12928 return D_O_K;
12929 }
12930
12931 int32_t onScrData()
12932 {
12933 restore_mouse();
12934 call_screendata_dialog();
12935 return D_O_K;
12936 }
12937
12938 const char *roomslist(int32_t index, int32_t *list_size)
12939 {
12940 if(index>=0)
12941 {
12942 if(index>=MAXROOMTYPES)
12943 index=MAXROOMTYPES-1;
12944
12945 return roomtype_string[index];
12946 }
12947
12948 *list_size=MAXROOMTYPES;
12949 return NULL;
12950 }
12951
12952 static char number_str_buf[MIDI_TRACK_BUFFER_SIZE];
12953 int32_t number_list_size=1;
12954 bool number_list_zero=false;
12955
12956 const char *numberlist(int32_t index, int32_t *list_size)
12957 {
12958 if(index>=0)
12959 {
12960 bound(index,0,number_list_size-1);
12961 sprintf(number_str_buf,"%d",index+(number_list_zero?0:1));
12962 return number_str_buf;
12963 }
12964
12965 *list_size=number_list_size;
12966 return NULL;
12967 }
12968
12969 static char dmap_str_buf[37];
12970 int32_t dmap_list_size=MAXDMAPS;
12971 bool dmap_list_zero=true;
12972
12973 const char *dmaplist(int32_t index, int32_t *list_size)
12974 {
12975 if(index>=0)
12976 {
12977 bound(index,0,dmap_list_size-1);
12978 sprintf(dmap_str_buf,"%3d-%s",index+(dmap_list_zero?0:1), DMaps[index].name);
12979 return dmap_str_buf;
12980 }
12981
12982 *list_size=dmap_list_size;
12983 return NULL;
12984 }
12985
12986 char *hexnumlist(int32_t index, int32_t *list_size)
12987 {
12988 if(index>=0)
12989 {
12990 bound(index,0,number_list_size-1);
12991 sprintf(number_str_buf,"%X",index+(number_list_zero?0:1));
12992 return number_str_buf;
12993 }
12994
12995 *list_size=number_list_size;
12996 return NULL;
12997 }
12998
12999 const char *maplist(int32_t index, int32_t *list_size)
13000 {
13001 if(index>=0)
13002 {
13003 bound(index,0,MAXMAPS-1);
13004 sprintf(number_str_buf,"%d",index+1);
13005 return number_str_buf;
13006 }
13007
13008 *list_size=MAXMAPS;
13009 return NULL;
13010 }
13011
13012 const char *gotomaplist(int32_t index, int32_t *list_size)
13013 {
13014 if(index>=0)
13015 {
13016 bound(index,0,map_count-1);
13017 sprintf(number_str_buf,"%d",index+1);
13018 return number_str_buf;
13019 }
13020
13021 *list_size = map_count;
13022 return NULL;
13023 }
13024
13025 const char *midilist(int32_t index, int32_t *list_size)
13026 {
13027 if(index>=0)
13028
13029 {
13030 bound(index,0,MAXCUSTOMMIDIS_ZQ-1);
13031 return midi_string[index];
13032 }
13033
13034 *list_size=MAXCUSTOMMIDIS_ZQ;
13035 return NULL;
13036 }
13037
13038 const char *custommidilist(int32_t index, int32_t *list_size)
13039 {
13040 if(index>=0)
13041 {
13042 bound(index,0,MAXCUSTOMMIDIS_ZQ-1);
13043 sprintf(number_str_buf,"%3d - %s",index+(number_list_zero?0:1),customtunes[index].data?customtunes[index].title:"(Empty)");
13044 return number_str_buf;
13045 }
13046
13047 *list_size=number_list_size;
13048 return NULL;
13049 }
13050
13051 const char *enhancedmusiclist(int32_t index, int32_t *list_size)
13052 {
13053 index=index; //this is here to prevent unused parameter warnings
13054 list_size=list_size; //this is here to prevent unused parameter warnings
13055 /*if(index>=0)
13056 {
13057 bound(index,0,MAXMUSIC-1);
13058 sprintf(number_str_buf,"%3d - %s",index+(number_list_zero?0:1),enhancedMusic[index].filename[0]?enhancedMusic[index].title:"(Empty)" );
13059 return number_str_buf;
13060 }
13061 *list_size=number_list_size;*/
13062 return NULL;
13063 }
13064
13065
13066 const char *levelnumlist(int32_t index, int32_t *list_size)
13067 {
13068 if(index>=0)
13069 {
13070 bound(index,0,0xFFF);
13071 sprintf(number_str_buf,"%.3X - %s",index,palnames[index]);
13072 return number_str_buf;
13073 }
13074
13075 *list_size=MAXLEVELS;
13076 return NULL;
13077 }
13078
13079 static char shop_str_buf[40];
13080 int32_t shop_list_size=1;
13081
13082 const char *shoplist(int32_t index, int32_t *list_size)
13083 {
13084 if(index>=0)
13085 {
13086 bound(index,0,shop_list_size-1);
13087 sprintf(shop_str_buf,"%3d: %s",index,QMisc.shop[index].name);
13088 return shop_str_buf;
13089 }
13090
13091 *list_size=shop_list_size;
13092 return NULL;
13093 }
13094
13095 static char bottle_str_buf[40];
13096 int32_t bottle_list_size=1;
13097
13098 const char *bottlelist(int32_t index, int32_t *list_size)
13099 {
13100 if(index>=0)
13101 {
13102 bound(index,0,bottle_list_size-1);
13103 sprintf(bottle_str_buf,"%2d: %s",index+1,QMisc.bottle_types[index].name);
13104 return bottle_str_buf;
13105 }
13106
13107 *list_size=bottle_list_size;
13108 return NULL;
13109 }
13110
13111 static char bottleshop_str_buf[40];
13112 int32_t bottleshop_list_size=1;
13113
13114 const char *bottleshoplist(int32_t index, int32_t *list_size)
13115 {
13116 if(index>=0)
13117 {
13118 bound(index,0,bottleshop_list_size-1);
13119 sprintf(bottleshop_str_buf,"%3d: %s",index,QMisc.bottle_shop_types[index].name);
13120 return bottleshop_str_buf;
13121 }
13122
13123 *list_size=bottleshop_list_size;
13124 return NULL;
13125 }
13126
13127 static char info_str_buf[40];
13128 int32_t info_list_size=1;
13129
13130 const char *infolist(int32_t index, int32_t *list_size)
13131 {
13132 if(index>=0)
13133 {
13134 bound(index,0,info_list_size-1);
13135 sprintf(info_str_buf,"%3d: %s",index,QMisc.info[index].name);
13136 return info_str_buf;
13137 }
13138
13139 *list_size=info_list_size;
13140 return NULL;
13141 }
13142
13143 bool mapcount_will_affect_layers(word newmapcount)
13144 {
13145 for(int32_t i=0; i<(newmapcount)*MAPSCRS; i++)
13146 {
13147 mapscr *layerchecker=&TheMaps[i];
13148
13149 for(int32_t j=0; j<6; j++)
13150 {
13151 if(layerchecker->layermap[j]>(newmapcount))
13152 {
13153 return true;
13154 }
13155 }
13156 }
13157 return false;
13158 }
13159
13160 void update_map_count(word newmapcount)
13161 {
13162 if(map_count == newmapcount) return;
13163 saved = false;
13164 setMapCount2(newmapcount);
13165 //Prevent the nine 'last mapscreen' buttons from pointing to invlid locations
13166 //if the user reduces the mapcount. -Z ( 23rd September, 2019 )
13167 for ( int32_t q = 0; q < 9; q++ )
13168 {
13169 map_page[q].map = ( map_page[q].map > newmapcount-1 ) ? newmapcount-1 : map_page[q].map;
13170 }
13171 for(int32_t i=0; i<(newmapcount)*MAPSCRS; i++)
13172 {
13173 fix_layers(&TheMaps[i], false);
13174 }
13175
13176 refresh(rMAP+rSCRMAP+rMENU);
13177 }
13178
13179 int32_t onGotoMap()
13180 {
13181 int32_t ret = select_data("Goto Map",Map.getCurrMap(),gotomaplist,get_zc_font(font_lfont));
13182
13183 if(ret >= 0)
13184 {
13185 int32_t m=Map.getCurrMap();
13186 Map.setCurrMap(ret);
13187 }
13188
13189 refresh(rALL);
13190 return D_O_K;
13191 }
13192
13193 int32_t onFlags()
13194 {
13195 restore_mouse();
13196 int32_t ret=select_cflag("Select Combo Flag",Flag);
13197 position_mouse_z(0);
13198
13199 if(ret>=0)
13200 {
13201 Flag=ret;
13202 refresh(rMENU);
13203 doflags();
13204 }
13205
13206 return D_O_K;
13207 }
13208
13209 static DIALOG usedcombo_list_dlg[] =
13210 {
13211 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
13212 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combos Used", NULL, NULL },
13213 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13214 12 { jwin_textbox_proc, 72-12, 60+4, 176+24+1, 92+4, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
13215 12 { jwin_button_proc, 130, 163, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13216 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13217 };
13218
13219
13220
13221 int32_t onUsedCombos()
13222 {
13223 restore_mouse();
13224 usedcombo_list_dlg[0].dp2=get_zc_font(font_lfont);
13225
13226 int32_t usedcombos[7][300][2];
13227 char combolist_text[65536];
13228 char temptext[80];
13229
13230 int32_t drawmap=Map.getCurrMap();
13231 int32_t drawscr=Map.getCurrScr();
13232 int32_t counter[7];
13233
13234 for(int32_t layer=0; layer<7; ++layer)
13235 {
13236 counter[layer]=0;
13237
13238 if(layer==0)
13239 {
13240 drawmap=Map.getCurrMap();
13241 drawscr=Map.getCurrScr();
13242 }
13243 else
13244 {
13245 drawmap=Map.CurrScr()->layermap[layer-1]-1;
13246 drawscr=Map.CurrScr()->layerscreen[layer-1];
13247 }
13248 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
13249 if(!draw_mapscr) continue;
13250
13251 usedcombos[layer][0][0]=draw_mapscr->data[0];
13252 usedcombos[layer][0][1]=1;
13253 counter[layer]=1;
13254
13255 for(int32_t i=1; i<176; ++i)
13256 {
13257 bool used=false;
13258
13259 for(int32_t j=0; j<counter[layer]; ++j)
13260 {
13261 if(usedcombos[layer][j][0]==draw_mapscr->data[i])
13262 {
13263 ++usedcombos[layer][j][1];
13264 used=true;
13265 break;
13266 }
13267 }
13268
13269 if(!used)
13270 {
13271 usedcombos[layer][counter[layer]][0]=draw_mapscr->data[i];
13272 usedcombos[layer][counter[layer]][1]=1;
13273 ++counter[layer];
13274 }
13275 }
13276
13277 for(int32_t i=0; i<counter[layer]-1; i++)
13278 {
13279 for(int32_t j=i+1; j<counter[layer]; j++)
13280 {
13281 if(usedcombos[layer][i][0]>usedcombos[layer][j][0])
13282 {
13283 zc_swap(usedcombos[layer][i][0],usedcombos[layer][j][0]);
13284 zc_swap(usedcombos[layer][i][1],usedcombos[layer][j][1]);
13285 }
13286 }
13287 }
13288 }
13289
13290 sprintf(combolist_text, " ");
13291
13292 for(int32_t layer=0; layer<7; ++layer)
13293 {
13294 if(counter[layer]>0)
13295 {
13296 if(layer>0)
13297 {
13298 strcat(combolist_text, "\n");
13299 }
13300
13301 sprintf(temptext, "Combos on layer %d\n-----------------\n", layer);
13302 strcat(combolist_text, temptext);
13303
13304 for(int32_t i=0; i<counter[layer]; i++)
13305 {
13306 if((i<counter[layer]-1) && (((usedcombos[layer][i][1]==usedcombos[layer][i+1][1]&&(usedcombos[layer][i][0]+1==usedcombos[layer][i+1][0])) && ((i==0) || ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0])))))))
13307 {
13308 sprintf(temptext, "%5d ", usedcombos[layer][i][0]);
13309 strcat(combolist_text, temptext);
13310 }
13311 else if(((i>0) && (((usedcombos[layer][i][1]==usedcombos[layer][i-1][1])&&((usedcombos[layer][i][0]-1==usedcombos[layer][i-1][0]))) && ((i==counter[layer]-1) || ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0])))))))
13312 {
13313 sprintf(temptext, "- %5d (%3d)\n", usedcombos[layer][i][0],usedcombos[layer][i][1]);
13314 strcat(combolist_text, temptext);
13315 }
13316 else if(((i==0) && ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0]))))||
13317 ((i==counter[layer]-1) && ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0]))))||
13318 ((i>0) && (i<counter[layer]-1) && ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0]))) && ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0])))))
13319 {
13320 sprintf(temptext, " %5d (%3d)\n", usedcombos[layer][i][0],usedcombos[layer][i][1]);
13321 strcat(combolist_text, temptext);
13322 }
13323 }
13324 }
13325 }
13326
13327 strcat(combolist_text, "\n");
13328 usedcombo_list_dlg[2].dp=combolist_text;
13329 usedcombo_list_dlg[2].d2=0;
13330
13331 large_dialog(usedcombo_list_dlg);
13332
13333 do_zqdialog(usedcombo_list_dlg,2);
13334 position_mouse_z(0);
13335 return D_O_K;
13336 }
13337
13338 int32_t onItem()
13339 {
13340 restore_mouse();
13341 int32_t exit_status;
13342 int32_t current_item=Map.CurrScr()->hasitem != 0 ? Map.CurrScr()->item : -1;
13343
13344 ItemListerDialog(current_item,true).show();
13345 if(current_item != lister_sel_val)
13346 {
13347 if(lister_sel_val>=0)
13348 {
13349 saved = false;
13350 Map.CurrScr()->item = lister_sel_val;
13351 Map.CurrScr()->hasitem = true;
13352 }
13353 else
13354 {
13355 saved = false;
13356 Map.CurrScr()->hasitem = false;
13357 }
13358 }
13359
13360 refresh(rMAP+rMENU);
13361 return D_O_K;
13362 }
13363
13364 void call_room_dlg(mapscr* scr);
13365 int32_t onRoom()
13366 {
13367 restore_mouse();
13368 auto* scr = Map.CurrScr();
13369 call_room_dlg(scr);
13370
13371 refresh(rMAP+rMENU);
13372 return D_O_K;
13373 }
13374
13375 int32_t onEndString()
13376 {
13377 int32_t ret=select_data("Select Ending String",QMisc.endstring,msgslist,get_zc_font(font_lfont));
13378
13379 if(ret>=0)
13380 {
13381 saved=false;
13382 QMisc.endstring=msglistcache[ret];
13383 }
13384
13385 refresh(rMENU);
13386 return D_O_K;
13387 }
13388
13389 12 static ListData levelnum_list(levelnumlist, &font);
13390
13391 static DIALOG screen_pal_dlg[] =
13392 {
13393 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
13394 12 { jwin_win_proc, 60-12, 40, 200-16, 96, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Palette", NULL, NULL },
13395 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13396 12 { jwin_droplist_proc, 72-12, 84+4, 161, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &levelnum_list, NULL, NULL },
13397 12 { jwin_button_proc, 70, 111, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13398 12 { jwin_button_proc, 150, 111, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13399 12 { jwin_text_proc, 72-12, 60+4, 168, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Note: This does not affect how the", NULL, NULL },
13400 12 { jwin_text_proc, 72-12, 72+4, 168, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "room will be displayed in-game!", NULL, NULL },
13401 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13402 };
13403 // return list_dlg[2].d1;
13404
13405 int32_t onScreenPalette()
13406 {
13407 restore_mouse();
13408 screen_pal_dlg[0].dp2=get_zc_font(font_lfont);
13409 auto oldcol = screen_pal_dlg[2].d1 = Map.getcolor();
13410
13411 large_dialog(screen_pal_dlg);
13412 auto old_valid = Map.CurrScr()->valid;
13413 pause_dlg_tint(true);
13414 zq_set_screen_never_freeze(true);
13415 while(true)
13416 {
13417 auto ret = do_zqdialog(screen_pal_dlg,2);
13418 if(ret == 2)
13419 {
13420 Map.setcolor(screen_pal_dlg[2].d1);
13421 refresh(rALL);
13422 }
13423 else
13424 {
13425 if(ret == 3)
13426 {
13427 if(screen_pal_dlg[2].d1 != oldcol)
13428 saved=false;
13429 Map.setcolor(screen_pal_dlg[2].d1);
13430 }
13431 else
13432 {
13433 Map.setcolor(oldcol);
13434 Map.CurrScr()->valid = old_valid;
13435 }
13436 refresh(rALL);
13437 break;
13438 }
13439 }
13440 pause_dlg_tint(false);
13441 zq_set_screen_never_freeze(false);
13442
13443 rebuild_trans_table();
13444
13445 return D_O_K;
13446 }
13447
13448 int32_t onDecScrPal()
13449 {
13450 if(DisableLPalShortcuts)
13451 {
13452 lpal_dsa();
13453 return D_O_K;
13454 }
13455 restore_mouse();
13456 int32_t c = Map.getcolor();
13457 c = (c+511) % 512;
13458 Map.setcolor(c);
13459 refresh(rALL);
13460 saved = false;
13461 return D_O_K;
13462 }
13463
13464 int32_t onIncScrPal()
13465 {
13466 if(DisableLPalShortcuts)
13467 {
13468 lpal_dsa();
13469 return D_O_K;
13470 }
13471 restore_mouse();
13472 int32_t c = Map.getcolor();
13473 c = (c+1)%512;
13474 Map.setcolor(c);
13475 refresh(rALL);
13476 saved = false;
13477 return D_O_K;
13478 }
13479
13480 int32_t PalWrap(int32_t kX, int32_t const kLowerBound, int32_t const kUpperBound)
13481 {
13482 int32_t range_size = kUpperBound - kLowerBound + 1;
13483
13484 if (kX < kLowerBound)
13485 kX += range_size * ((kLowerBound - kX) / range_size + 1);
13486
13487 return kLowerBound + (kX - kLowerBound) % range_size;
13488 }
13489
13490 int32_t onDecScrPal16()
13491 {
13492 if(DisableLPalShortcuts)
13493 {
13494 lpal_dsa();
13495 return D_O_K;
13496 }
13497 restore_mouse();
13498 int32_t c = Map.getcolor();
13499 c = PalWrap( ( c-0x10 ), 0, 511 );
13500 Map.setcolor(c);
13501 refresh(rALL);
13502 saved = false;
13503 return D_O_K;
13504 }
13505
13506 int32_t onIncScrPal16()
13507 {
13508 if(DisableLPalShortcuts)
13509 {
13510 lpal_dsa();
13511 return D_O_K;
13512 }
13513 restore_mouse();
13514 int32_t c = Map.getcolor();
13515 c = PalWrap( ( c+0x10 ), 0, 511 );
13516 Map.setcolor(c);
13517 refresh(rALL);
13518 saved = false;
13519 return D_O_K;
13520 }
13521
13522 int32_t onZoomIn()
13523 {
13524 change_mapscr_zoom(-1);
13525 return D_O_K;
13526 }
13527
13528 int32_t onZoomOut()
13529 {
13530 change_mapscr_zoom(1);
13531 return D_O_K;
13532 }
13533
13534 int32_t d_ndroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13535 {
13536 int32_t ret = jwin_droplist_proc(msg,d,c);
13537
13538 // The only place this proc is used is in the info type editor.
13539 // If it's ever used anywhere else, this will probably need to be changed.
13540 // Maybe add a flag for it or something.
13541 int32_t msgID=msg_at_pos(d->d1);
13542
13543 switch(msg)
13544 {
13545 case MSG_DRAW:
13546 case MSG_CHAR:
13547 case MSG_CLICK:
13548 textprintf_ex(screen,font,d->x - 48,d->y + 4,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%5d",msgID);
13549 }
13550
13551 return ret;
13552 }
13553
13554 int32_t d_idroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13555 {
13556 int32_t ret = jwin_droplist_proc(msg,d,c);
13557
13558 switch(msg)
13559 {
13560 case MSG_DRAW:
13561 case MSG_CHAR:
13562 case MSG_CLICK:
13563 int32_t tile = bii[d->d1].i >=0 ? itemsbuf[bii[d->d1].i].tile : 0;
13564 int32_t cset = bii[d->d1].i >=0 ? itemsbuf[bii[d->d1].i].csets&15 : 0;
13565 int32_t x = d->x + d->w + 4;
13566 int32_t y = d->y - 8;
13567 int32_t w = 32;
13568 int32_t h = 32;
13569
13570 BITMAP *buf = create_bitmap_ex(8,16,16);
13571 BITMAP *bigbmp = create_bitmap_ex(8,w,h);
13572
13573 if(buf && bigbmp)
13574 {
13575 clear_bitmap(buf);
13576
13577 if(tile)
13578 overtile16(buf, tile,0,0,cset,0);
13579
13580 stretch_blit(buf, bigbmp, 0,0, 16, 16, 0, 0, w, h);
13581 destroy_bitmap(buf);
13582 jwin_draw_frame(screen,x,y,w+4,h+4,FR_DEEP);
13583 blit(bigbmp,screen,0,0,x+2,y+2,w,h);
13584 destroy_bitmap(bigbmp);
13585 }
13586
13587 }
13588
13589 return ret;
13590 }
13591
13592 int32_t d_nidroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13593 {
13594 int32_t ret = d_idroplist_proc(msg,d,c);
13595
13596 switch(msg)
13597 {
13598 case MSG_DRAW:
13599 case MSG_CHAR:
13600 case MSG_CLICK:
13601 textprintf_ex(screen,font,d->x - 48,d->y + 4,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%5d",bii[d->d1].i);
13602 }
13603
13604 return ret;
13605 }
13606
13607 // Triforce pieces
13608 static byte triframe_points[9*4] =
13609 {
13610 0,2,2,0, 2,0,4,2, 0,2,4,2, 1,1,3,1, 2,0,2,2,
13611 1,1,1,2, 1,1,2,2, 3,1,3,2, 3,1,2,2
13612 };
13613
13614 int32_t d_tri_frame_proc(int32_t msg,DIALOG *d,int32_t c)
13615 {
13616 //these are here to bypass compiler warnings about unused arguments
13617 c=c;
13618
13619 if(msg==MSG_DRAW)
13620 {
13621 int32_t x[5],y[3];
13622
13623 x[0]=d->x;
13624 x[1]=d->x+(d->w>>2);
13625 x[2]=d->x+(d->w>>1);
13626 x[3]=d->x+(d->w>>1)+(d->w>>2);
13627 x[4]=d->x+d->w;
13628 y[0]=d->y;
13629 y[1]=d->y+(d->h>>1);
13630 y[2]=d->y+d->h;
13631
13632 byte *p = triframe_points;
13633
13634 for(int32_t i=0; i<9; i++)
13635 {
13636 line(screen,x[*p],y[*(p+1)],x[*(p+2)],y[*(p+3)],d->fg);
13637 p+=4;
13638 }
13639 }
13640
13641 return D_O_K;
13642 }
13643
13644 int32_t d_tri_edit_proc(int32_t msg,DIALOG *d,int32_t c)
13645 {
13646 jwin_button_proc(msg,d,c);
13647
13648 if(msg==MSG_CLICK)
13649 {
13650 int32_t v = getnumber("Piece Number",d->d1);
13651
13652 if(v>=0)
13653 {
13654 bound(v,1,8);
13655
13656 if(v!=d->d1)
13657 {
13658 DIALOG *tp = d - d->d2;
13659
13660 for(int32_t i=0; i<8; i++)
13661 {
13662 if(tp->d1==v)
13663 {
13664 tp->d1 = d->d1;
13665 ((char*)(tp->dp))[0] = d->d1+'0';
13666 jwin_button_proc(MSG_DRAW,tp,0);
13667 }
13668
13669 ++tp;
13670 }
13671
13672 d->d1 = v;
13673 ((char*)(d->dp))[0] = v+'0';
13674 }
13675 }
13676
13677 d->flags = 0;
13678 jwin_button_proc(MSG_DRAW,d,0);
13679 }
13680
13681 return D_O_K;
13682 }
13683
13684 static DIALOG tp_dlg[] =
13685 {
13686 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
13687 12 { jwin_win_proc, 56, 32, 208, 160, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
13688 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13689 12 { d_tri_frame_proc, 64, 56, 192, 96, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, NULL, NULL, NULL },
13690 // 3
13691 12 { d_tri_edit_proc, 138, 82, 17, 17, vc(14), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
13692 12 { d_tri_edit_proc, 166, 82, 17, 17, vc(14), vc(1), 0, 0, 0, 1, (void *) "2", NULL, NULL },
13693 12 { d_tri_edit_proc, 90, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 2, (void *) "3", NULL, NULL },
13694 12 { d_tri_edit_proc, 214, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 3, (void *) "4", NULL, NULL },
13695 // 7
13696 12 { d_tri_edit_proc, 138, 110, 17, 17, vc(14), vc(1), 0, 0, 0, 4, (void *) "5", NULL, NULL },
13697 12 { d_tri_edit_proc, 118, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 5, (void *) "6", NULL, NULL },
13698 12 { d_tri_edit_proc, 166, 110, 17, 17, vc(14), vc(1), 0, 0, 0, 6, (void *) "7", NULL, NULL },
13699 12 { d_tri_edit_proc, 186, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 7, (void *) "8", NULL, NULL },
13700 // 11
13701 12 { jwin_button_proc, 90, 166, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13702 12 { jwin_button_proc, 170, 166, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13703 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13704 };
13705
13706 int32_t onTriPieces()
13707 {
13708 tp_dlg[0].dp2=get_zc_font(font_lfont);
13709 char temptext[8][2];
13710
13711 for(int32_t i=0; i<8; i++)
13712 {
13713 tp_dlg[i+3].d1 = QMisc.triforce[i];
13714 // ((char*)(tp_dlg[i+3].dp))[0] = QMisc.triforce[i]+'0';
13715 sprintf(temptext[i], "%d", QMisc.triforce[i]);
13716 tp_dlg[i+3].dp=temptext[i];
13717 }
13718
13719 large_dialog(tp_dlg);
13720
13721 if(do_zqdialog(tp_dlg,-1) == 11)
13722 {
13723 saved=false;
13724
13725 for(int32_t i=0; i<8; i++)
13726 QMisc.triforce[i] = tp_dlg[i+3].d1;
13727 }
13728
13729 return D_O_K;
13730 }
13731
13732 int32_t d_maptile_proc(int32_t msg,DIALOG *d,int32_t c);
13733 bool small_dmap=false;
13734
13735 static DIALOG dmapmaps_dlg[] =
13736 {
13737
13738 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
13739 { jwin_win_proc, 4, 18, 313, 217, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Custom DMap Map Styles", NULL, NULL },
13740 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13741 { jwin_button_proc, 93, 208, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13742 { jwin_button_proc, 168, 208, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13743 { d_ctext2_proc, 160, 38, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimaps", NULL, NULL },
13744 { d_ctext2_proc, 112, 46, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Without Map", NULL, NULL },
13745 { d_ctext2_proc, 208, 46, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "With Map", NULL, NULL },
13746
13747 { d_ctext2_proc, 162, 110, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Large Maps", NULL, NULL },
13748 { d_ctext2_proc, 80, 118, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Without Map", NULL, NULL },
13749 { d_ctext2_proc, 240, 118, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "With Map", NULL, NULL },
13750 // 5
13751 { d_maptile_proc, 72, 54, 80, 48, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13752 { d_maptile_proc, 168, 54, 80, 48, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13753 { d_maptile_proc, 8, 126, 144, 80, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13754 { d_maptile_proc, 168, 126, 144, 80, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13755 // 11
13756 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13757 };
13758
13759 int32_t d_hexedit_proc(int32_t msg,DIALOG *d,int32_t c)
13760 {
13761 return jwin_hexedit_proc(msg,d,c);
13762 }
13763
13764 void drawgrid(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t fg,int32_t bg,int32_t div)
13765 {
13766 if(div!=-1)
13767 rectfill(dest,x-1,y-1,x+63,y+3,div);
13768
13769 for(int32_t dx=0; dx<64; dx+=8)
13770 {
13771 if(grid&0x80)
13772 rectfill(dest,x+dx,y,x+dx+6,y+2,fg);
13773 else if(bg!=-1)
13774 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13775
13776 grid<<=1;
13777 }
13778 }
13779
13780 void drawovergrid(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t color,int32_t div)
13781 {
13782 if(div!=-1)
13783 rectfill(dest,x-1,y-1,x+63,y+3,div);
13784
13785 for(int32_t dx=0; dx<64; dx+=4)
13786 {
13787 rectfill(dest,x+dx,y,x+dx+2,y+2,color);
13788 grid<<=1;
13789 }
13790 }
13791
13792 void drawgrid(BITMAP *dest,int32_t x,int32_t y,int32_t w, int32_t h, int32_t tw, int32_t th, int32_t *grid,int32_t fg,int32_t bg,int32_t div)
13793 {
13794 //these are here to bypass compiler warnings about unused arguments
13795 w=w;
13796 tw=tw;
13797 th=th;
13798
13799 rectfill(dest,x,y,x+(8*8),y+(1*4),div);
13800
13801 for(int32_t dy=0; dy<h; dy++)
13802 {
13803 for(int32_t dx=0; dx<64; dx+=8)
13804 {
13805 if(grid[0]&0x80)
13806 rectfill(dest,x+dx,y,x+dx+6,y+2,fg);
13807 else
13808 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13809
13810 grid[0]<<=1;
13811 }
13812 }
13813 }
13814
13815 void drawgrid_s(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t fg,int32_t bg,int32_t div)
13816 {
13817 rectfill(dest,x-1,y-1,x+63,y+3,div);
13818
13819 for(int32_t dx=0; dx<64; dx+=8)
13820 {
13821 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13822
13823 if(grid&0x80)
13824 rectfill(dest,x+dx+2,y,x+dx+4,y+2,fg);
13825
13826 grid<<=1;
13827 }
13828 }
13829
13830 void drawdmap(int32_t dmap)
13831 {
13832 int32_t c;
13833 zcolors mc=QMisc.colors;
13834
13835 switch((DMaps[dmap].type&dmfTYPE))
13836 {
13837 case dmDNGN:
13838 case dmCAVE:
13839 clear_bitmap(dmapbmp_small);
13840
13841 if(DMaps[dmap].minimap_tile[1])
13842 ;
13843 // overworld_map_tile overrides the NES minimap. dungeon_map_tile does not.
13844 else for(int32_t y=1; y<33; y+=4)
13845 drawgrid(dmapbmp_small,0,y,DMaps[dmap].grid[y>>2], DMaps[dmap].flags&dmfMINIMAPCOLORFIX ? mc.cave_fg : mc.dngn_fg, -1, -1);
13846
13847 c=DMaps[dmap].compass;
13848 // rectfill(dmapbmp,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,dvc(2*4));
13849 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(4));
13850 c=DMaps[dmap].cont;
13851 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(10));
13852 break;
13853
13854 case dmOVERW:
13855 clear_bitmap(dmapbmp_small);
13856
13857 if(DMaps[dmap].minimap_tile[1])
13858 ;
13859 else if(!mc.overworld_map_tile)
13860 for(int32_t y=1; y<33; y+=4)
13861 drawovergrid(dmapbmp_small,1,y,DMaps[dmap].grid[y>>2],mc.overw_bg,vc(0));
13862
13863 c=DMaps[dmap].cont;
13864 rectfill(dmapbmp_small,(c&15)*4+1,(c>>4)*4+1,(c&15)*4+3,(c>>4)*4+3,vc(10));
13865 break;
13866
13867 case dmBSOVERW:
13868 clear_bitmap(dmapbmp_small);
13869
13870 if(DMaps[dmap].minimap_tile[1])
13871 ;
13872 else if(!mc.overworld_map_tile)
13873 for(int32_t y=1; y<33; y+=4)
13874 // drawgrid_s(dmapbmp,1,y,DMaps[dmap].grid[y>>2],dvc(2*4),dvc(2*3),dvc(3+4));
13875 drawgrid_s(dmapbmp_small,0,y,DMaps[dmap].grid[y>>2],mc.bs_goal,mc.bs_dk,vc(14));
13876
13877 c=DMaps[dmap].cont;
13878 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(10));
13879 break;
13880 }
13881 }
13882
13883 void drawdmap_screen(int32_t x, int32_t y, int32_t w, int32_t h, int32_t dmap)
13884 {
13885 BITMAP *tempbmp = create_bitmap_ex(8,w,h);
13886 clear_to_color(tempbmp, vc(0));
13887 zcolors mc=QMisc.colors;
13888
13889 // rectfill(tempbmp,x,y,x+w-1,y+h-1,vc(0));
13890
13891 if(DMaps[dmap].minimap_tile[1])
13892 {
13893 draw_block(tempbmp,0,0,DMaps[dmap].minimap_tile[1],DMaps[dmap].minimap_cset[1],5,3);
13894 }
13895 else if(((DMaps[dmap].type&dmfTYPE)==dmDNGN || (DMaps[dmap].type&dmfTYPE)==dmCAVE) && mc.dungeon_map_tile)
13896 {
13897 draw_block(tempbmp,0,0,mc.dungeon_map_tile,mc.dungeon_map_cset,5,3);
13898 }
13899 else if(((DMaps[dmap].type&dmfTYPE)==dmOVERW || (DMaps[dmap].type&dmfTYPE)==dmBSOVERW) && mc.overworld_map_tile)
13900 {
13901 draw_block(tempbmp,0,0,mc.overworld_map_tile,mc.overworld_map_cset,5,3);
13902 }
13903
13904 masked_blit(dmapbmp_small,tempbmp,0,0,8,7,65,33);
13905
13906 blit(tempbmp,screen,0,0,x,y,w,h);
13907 destroy_bitmap(tempbmp);
13908
13909 }
13910
13911 int32_t d_dmaplist_proc(int32_t msg,DIALOG *d,int32_t c)
13912 {
13913 if(msg==MSG_DRAW)
13914 {
13915 int32_t dmap = d->d1;
13916 int32_t xy[6] = {44,92,128,100,128,110};
13917 //int32_t *xy = (int32_t*)(d->dp3);
13918 float temp_scale = 1.5;
13919
13920 drawdmap(dmap);
13921
13922 if(xy[0]>-1000&&xy[1]>-1000)
13923 {
13924 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
13925 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
13926 int32_t w = 84;
13927 int32_t h = 52;
13928 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
13929 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
13930 }
13931
13932 if(xy[2]>-1000&&xy[3]>-1000)
13933 {
13934 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[2])*temp_scale),d->y+int32_t((xy[3])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %-3d",DMaps[d->d1].map+1);
13935 }
13936
13937 if(xy[4]>-1000&&xy[5]>-1000)
13938 {
13939 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[4])*temp_scale),d->y+int32_t((xy[5])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level: %-3d",DMaps[d->d1].level);
13940 }
13941 }
13942
13943 return jwin_list_proc(msg,d,c);
13944 }
13945
13946 int32_t d_dropdmaplist_proc(int32_t msg,DIALOG *d,int32_t c)
13947 {
13948 if(msg==MSG_DRAW)
13949 {
13950 int32_t dmap = d->d1;
13951 int32_t *xy = (int32_t*)(d->dp3);
13952 float temp_scale = 1.5;
13953
13954 drawdmap(dmap);
13955
13956 if(xy[0]>-1000&&xy[1]>-1000)
13957 {
13958 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
13959 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
13960 int32_t w = 84;
13961 int32_t h = 52;
13962 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
13963 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
13964 }
13965
13966 if(xy[2]>-1000&&xy[3]>-1000)
13967 {
13968 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[2])*temp_scale),d->y+int32_t((xy[3])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %-3d",DMaps[d->d1].map+1);
13969 }
13970
13971 if(xy[4]>-1000&&xy[5]>-1000)
13972 {
13973 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[4])*temp_scale),d->y+int32_t((xy[5])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level: %-3d",DMaps[d->d1].level);
13974 }
13975 }
13976
13977 return jwin_droplist_proc(msg,d,c);
13978 }
13979
13980 void drawxmap(ALLEGRO_BITMAP* dest, int32_t themap, int32_t xoff, bool large, int dx, int dy)
13981 {
13982 ALLEGRO_STATE old_state;
13983 al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP);
13984
13985 al_set_target_bitmap(dest);
13986 al_clear_to_color(al_map_rgba(0, 0, 0, 0));
13987
13988 int32_t cols = (large ? 8 : 16);
13989 int32_t col_width = large ? 22 : 11;
13990 int32_t dot_width = (large ? 6 : 4);
13991 int32_t dot_offset = (large ? 7 : 3);
13992 int32_t l = 10;
13993
13994 for (int32_t y = 0; y < 8; y++)
13995 {
13996 // Users might have set the dmap to a map that has since been deleted.
13997 if (themap >= Map.getMapCount())
13998 break;
13999
14000 for (int32_t x = 0; x < cols; x++)
14001 {
14002 if (x + xoff < 0 || x + xoff > 15)
14003 continue;
14004
14005 const mapscr* scr = get_canonical_scr(themap, y * 16 + x + (large ? xoff : 0));
14006 if (!(scr->valid & mVALID))
14007 continue;
14008
14009 al_draw_filled_rectangle(dx + (x * col_width), dy + (y * l), dx + (x * col_width + col_width), dy + ((y * l) + l), real_lc1(scr->color));
14010 al_draw_filled_rectangle(dx + (x * col_width + dot_offset), dy + (y * l + 3), dx + (x * col_width + dot_offset + dot_width), dy + (y * l + l - 3), real_lc2(scr->color));
14011 }
14012 }
14013
14014 al_restore_state(&old_state);
14015 }
14016
14017 const char *dmapscriptdroplist(int32_t index, int32_t *list_size)
14018 {
14019 if(index<0)
14020 {
14021 *list_size = bidmaps_cnt;
14022 return NULL;
14023 }
14024
14025 return bidmaps[index].first.c_str();
14026 }
14027
14028 12 static ListData dmapscript_list(dmapscriptdroplist, &a4fonts[font_pfont]);
14029
14030 //int32_t selectdmapxy[6] = {90,142,164,150,164,160};
14031 int32_t selectdmapxy[6] = {44,92,128,100,128,110};
14032
14033 12 static ListData dmap_list(dmaplist, &font);
14034
14035 12 static dmap copiedDMap;
14036 static byte dmapcopied = 0;
14037
14038 int32_t writesomedmaps(PACKFILE *f, int32_t first, int32_t last, int32_t max)
14039 {
14040
14041 dword section_version=V_DMAPS;
14042 int32_t zversion = ZELDA_VERSION;
14043 int32_t zbuild = VERSION_BUILD;
14044
14045 if(!p_iputl(V_ZDMAP,f))
14046 {
14047 return 0;
14048 }
14049
14050 //section version info
14051 if(!p_iputl(zversion,f))
14052 {
14053 return 0;
14054 }
14055 if(!p_iputl(zbuild,f))
14056 {
14057 return 0;
14058 }
14059 if(!p_iputw(section_version,f))
14060 {
14061 new_return(2);
14062 }
14063
14064 if(!write_deprecated_section_cversion(section_version, f))
14065 {
14066 new_return(3);
14067 }
14068 //max possible at this time
14069 if(!p_iputl(max,f))
14070 {
14071 new_return(4);
14072 }
14073 //first id written
14074 if(!p_iputl(first,f))
14075 {
14076 new_return(5);
14077 }
14078 //last id written
14079 if(!p_iputl(last,f))
14080 {
14081 new_return(6);
14082 }
14083 int32_t count = last-first;
14084 //number written
14085 if(!p_iputl(count,f))
14086 {
14087 new_return(7);
14088 }
14089
14090
14091 for ( int32_t i = first; i <= last; ++i )
14092 {
14093 if ( i > max ) break;
14094
14095 if(!p_putc(DMaps[i].map,f))
14096 {
14097 new_return(8);
14098 }
14099
14100 if(!p_iputw(DMaps[i].level,f))
14101 {
14102 new_return(9);
14103 }
14104
14105 if(!p_putc(DMaps[i].xoff,f))
14106 {
14107 new_return(10);
14108 }
14109
14110 if(!p_putc(DMaps[i].compass,f))
14111 {
14112 new_return(11);
14113 }
14114
14115 if(!p_iputw(DMaps[i].color,f))
14116 {
14117 new_return(12);
14118 }
14119
14120 if(!p_putc(DMaps[i].midi,f))
14121 {
14122 new_return(13);
14123 }
14124
14125 if(!p_putc(DMaps[i].cont,f))
14126 {
14127 new_return(14);
14128 }
14129
14130 if(!p_putc(DMaps[i].type,f))
14131 {
14132 new_return(15);
14133 }
14134
14135 for(int32_t j=0; j<8; j++)
14136 {
14137 if(!p_putc(DMaps[i].grid[j],f))
14138 {
14139 new_return(16);
14140 }
14141 }
14142
14143 //16
14144 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
14145 {
14146 new_return(17);
14147 }
14148
14149 if(!p_putwstr(DMaps[i].title,f))
14150 {
14151 new_return(18);
14152 }
14153
14154 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
14155 {
14156 new_return(19);
14157 }
14158
14159 if(!p_iputl(DMaps[i].minimap_tile[0],f))
14160 {
14161 new_return(20);
14162 }
14163
14164 if(!p_putc(DMaps[i].minimap_cset[0],f))
14165 {
14166 new_return(21);
14167 }
14168
14169 if(!p_iputl(DMaps[i].minimap_tile[1],f))
14170 {
14171 new_return(22);
14172 }
14173
14174 if(!p_putc(DMaps[i].minimap_cset[1],f))
14175 {
14176 new_return(23);
14177 }
14178
14179 if(!p_iputl(DMaps[i].largemap_tile[0],f))
14180 {
14181 new_return(24);
14182 }
14183
14184 if(!p_putc(DMaps[i].largemap_cset[0],f))
14185 {
14186 new_return(25);
14187 }
14188
14189 if(!p_iputl(DMaps[i].largemap_tile[1],f))
14190 {
14191 new_return(26);
14192 }
14193
14194 if(!p_putc(DMaps[i].largemap_cset[1],f))
14195 {
14196 new_return(27);
14197 }
14198
14199 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
14200 {
14201 new_return(28);
14202 }
14203
14204 if(!p_putc(DMaps[i].tmusictrack,f))
14205 {
14206 new_return(29);
14207 }
14208
14209 if(!p_putc(DMaps[i].active_subscreen,f))
14210 {
14211 new_return(30);
14212 }
14213
14214 if(!p_putc(DMaps[i].passive_subscreen,f))
14215 {
14216 new_return(31);
14217 }
14218
14219 byte disabled[32];
14220 memset(disabled,0,32);
14221
14222 for(int32_t j=0; j<MAXITEMS; j++)
14223 {
14224 if(DMaps[i].disableditems[j])
14225 {
14226 disabled[j/8] |= (1 << (j%8));
14227 }
14228 }
14229
14230 if(!pfwrite(disabled,32,f))
14231 {
14232 new_return(32);
14233 }
14234
14235 if(!p_iputl(DMaps[i].flags,f))
14236 {
14237 new_return(33);
14238 }
14239 if(!p_putc(DMaps[i].sideview,f))
14240 {
14241 new_return(30);
14242 }
14243 if(!p_iputw(DMaps[i].script,f))
14244 {
14245 new_return(31);
14246 }
14247 for ( int32_t q = 0; q < 8; q++ )
14248 {
14249 if(!p_iputl(DMaps[i].initD[q],f))
14250 {
14251 new_return(32);
14252 }
14253
14254 }
14255 for ( int32_t q = 0; q < 8; q++ )
14256 {
14257 for ( int32_t w = 0; w < 65; w++ )
14258 {
14259 if (!p_putc(DMaps[i].initD_label[q][w],f))
14260 {
14261 new_return(33);
14262 }
14263 }
14264 }
14265 if(!p_iputw(DMaps[i].active_sub_script,f))
14266 {
14267 new_return(34);
14268 }
14269 if(!p_iputw(DMaps[i].passive_sub_script,f))
14270 {
14271 new_return(35);
14272 }
14273 for(int32_t q = 0; q < 8; ++q)
14274 {
14275 if(!p_iputl(DMaps[i].sub_initD[q],f))
14276 {
14277 new_return(36);
14278 }
14279 }
14280 for(int32_t q = 0; q < 8; ++q)
14281 {
14282 for(int32_t w = 0; w < 65; ++w)
14283 {
14284 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
14285 {
14286 new_return(37);
14287 }
14288 }
14289 }
14290 if(!p_iputw(DMaps[i].onmap_script,f))
14291 {
14292 new_return(35);
14293 }
14294 for(int32_t q = 0; q < 8; ++q)
14295 {
14296 if(!p_iputl(DMaps[i].onmap_initD[q],f))
14297 {
14298 new_return(36);
14299 }
14300 }
14301 for(int32_t q = 0; q < 8; ++q)
14302 {
14303 for(int32_t w = 0; w < 65; ++w)
14304 {
14305 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
14306 {
14307 new_return(37);
14308 }
14309 }
14310 }
14311 if (!p_iputw(DMaps[i].mirrorDMap, f))
14312 {
14313 new_return(38);
14314 }
14315 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
14316 {
14317 new_return(39);
14318 }
14319 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
14320 {
14321 new_return(40);
14322 }
14323 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
14324 {
14325 new_return(41);
14326 }
14327 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
14328 {
14329 new_return(42);
14330 }
14331 }
14332
14333 return 1;
14334 }
14335
14336
14337 int32_t readsomedmaps(PACKFILE *f)
14338 {
14339 dword section_version = 0;
14340 int32_t zversion = 0;
14341 int32_t zbuild = 0;
14342 dmap tempdmap{};
14343
14344 int32_t first = 0, last = 0, max = 0, count = 0;
14345 int32_t datatype_version = 0;
14346
14347 //char dmapstring[64]={0};
14348 //section version info
14349 if(!p_igetl(&datatype_version,f))
14350 {
14351 return 0;
14352 }
14353 if ( datatype_version < 0 )
14354 {
14355 if(!p_igetl(&zversion,f))
14356 {
14357 return 0;
14358 }
14359 }
14360 else
14361 {
14362 zversion = datatype_version;
14363 }
14364 if(!p_igetl(&zbuild,f))
14365 {
14366 return 0;
14367 }
14368
14369 if(!p_igetw(&section_version,f))
14370 {
14371 return 0;
14372 }
14373
14374 if(!read_deprecated_section_cversion(f))
14375 {
14376 return 0;
14377 }
14378 if ( datatype_version < 0 )
14379 {
14380 if(!p_igetl(&max,f))
14381 {
14382 return 0;
14383 }
14384 if(!p_igetl(&first,f))
14385 {
14386 return 0;
14387 }
14388 if(!p_igetl(&last,f))
14389 {
14390 return 0;
14391 }
14392 if(!p_igetl(&count,f))
14393 {
14394 return 0;
14395 }
14396 }
14397 else
14398 {
14399 first = 0;
14400 last = 0;
14401 count = 1;
14402 max = 255;
14403 }
14404
14405
14406
14407
14408 al_trace("readsomedmaps section_version: %d\n", section_version);
14409
14410 if ( zversion > ZELDA_VERSION )
14411 {
14412 al_trace("Cannot read .zdmap packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
14413 return 0;
14414 }
14415 else if (( section_version > V_DMAPS ))
14416 {
14417 al_trace("Cannot read .zdmap packfile made using V_DMAPS (%d)\n", section_version);
14418 return 0;
14419 }
14420 else
14421 {
14422 al_trace("Reading a .zdmap packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
14423 }
14424 //if(!pfread(&dmapstring, 64, f))
14425 //{
14426 // return 0;
14427 //}
14428
14429
14430
14431 for ( int32_t i = first; i <= last; ++i )
14432 {
14433 if(!p_getc(&tempdmap.map,f))
14434 {
14435 return 0;
14436 }
14437
14438 if(!p_igetw(&tempdmap.level,f))
14439 {
14440 return 0;
14441 }
14442
14443 if(!p_getc(&tempdmap.xoff,f))
14444 {
14445 return 0;
14446 }
14447
14448 if(!p_getc(&tempdmap.compass,f))
14449 {
14450 return 0;
14451 }
14452
14453 if(!p_igetw(&tempdmap.color,f))
14454 {
14455 return 0;
14456 }
14457
14458 if(!p_getc(&tempdmap.midi,f))
14459 {
14460 return 0;
14461 }
14462
14463 if(!p_getc(&tempdmap.cont,f))
14464 {
14465 return 0;
14466 }
14467
14468 if(!p_getc(&tempdmap.type,f))
14469 {
14470 return 0;
14471 }
14472
14473 for(int32_t j=0; j<8; j++)
14474 {
14475 if(!p_getc(&tempdmap.grid[j],f))
14476 {
14477 return 0;
14478 }
14479 }
14480
14481 //16
14482 if(!pfread(&tempdmap.name,sizeof(DMaps[0].name),f))
14483 {
14484 return 0;
14485 }
14486
14487 if (section_version<20)
14488 {
14489 char title[22];
14490 if (!p_getstr(title, sizeof(title) - 1, f))
14491 {
14492 return 0;
14493 }
14494 tempdmap.title.assign(title);
14495 }
14496 else
14497 {
14498 if (!p_getwstr(&tempdmap.title, f))
14499 {
14500 return 0;
14501 }
14502 }
14503
14504 if(!pfread(&tempdmap.intro,sizeof(DMaps[0].intro),f))
14505 {
14506 return 0;
14507 }
14508
14509 if(!p_igetl(&tempdmap.minimap_tile[0],f))
14510 {
14511 return 0;
14512 }
14513
14514 if(!p_getc(&tempdmap.minimap_cset[0],f))
14515 {
14516 return 0;
14517 }
14518
14519 if(!p_igetl(&tempdmap.minimap_tile[1],f))
14520 {
14521 return 0;
14522 }
14523
14524 if(!p_getc(&tempdmap.minimap_cset[1],f))
14525 {
14526 return 0;
14527 }
14528
14529 if(!p_igetl(&tempdmap.largemap_tile[0],f))
14530 {
14531 return 0;
14532 }
14533
14534 if(!p_getc(&tempdmap.largemap_cset[0],f))
14535 {
14536 return 0;
14537 }
14538
14539 if(!p_igetl(&tempdmap.largemap_tile[1],f))
14540 {
14541 return 0;
14542 }
14543
14544 if(!p_getc(&tempdmap.largemap_cset[1],f))
14545 {
14546 return 0;
14547 }
14548
14549 if(!pfread(&tempdmap.tmusic,sizeof(DMaps[0].tmusic),f))
14550 {
14551 return 0;
14552 }
14553
14554 if(!p_getc(&tempdmap.tmusictrack,f))
14555 {
14556 return 0;
14557 }
14558
14559 if(!p_getc(&tempdmap.active_subscreen,f))
14560 {
14561 return 0;
14562 }
14563
14564 if(!p_getc(&tempdmap.passive_subscreen,f))
14565 {
14566 return 0;
14567 }
14568
14569 byte disabled[32];
14570 memset(disabled,0,32);
14571
14572 if(!pfread(&disabled, 32, f)) return 0;
14573
14574 for(int32_t j=0; j<MAXITEMS; j++)
14575 {
14576 if(disabled[j/8] & (1 << (j%8))) tempdmap.disableditems[j]=1;
14577 else tempdmap.disableditems[j]=0;
14578 }
14579
14580
14581 if(!p_igetl(&tempdmap.flags,f))
14582 {
14583 return 0;
14584 }
14585 if ( zversion >= 0x255 )
14586 {
14587 if ( section_version >= 14 )
14588 {
14589 //2.55 starts here
14590 if(!p_getc(&tempdmap.sideview,f))
14591 {
14592 return 0;
14593 }
14594 if(!p_igetw(&tempdmap.script,f))
14595 {
14596 return 0;
14597 }
14598 for ( int32_t q = 0; q < 8; q++ )
14599 {
14600 if(!p_igetl(&tempdmap.initD[q],f))
14601 {
14602 return 0;
14603 }
14604
14605 }
14606 for ( int32_t q = 0; q < 8; q++ )
14607 {
14608 for ( int32_t w = 0; w < 65; w++ )
14609 {
14610 if (!p_getc(&tempdmap.initD_label[q][w],f))
14611 {
14612 return 0;
14613 }
14614 }
14615 }
14616 if(!p_igetw(&tempdmap.active_sub_script,f))
14617 {
14618 return 0;
14619 }
14620 if(!p_igetw(&tempdmap.passive_sub_script,f))
14621 {
14622 return 0;
14623 }
14624 for(int32_t q = 0; q < 8; ++q)
14625 {
14626 if(!p_igetl(&tempdmap.sub_initD[q],f))
14627 {
14628 return 0;
14629 }
14630 }
14631 for(int32_t q = 0; q < 8; ++q)
14632 {
14633 for(int32_t w = 0; w < 65; ++w)
14634 {
14635 if(!p_getc(&tempdmap.sub_initD_label[q][w],f))
14636 {
14637 return 0;
14638 }
14639 }
14640 }
14641 if(!p_igetw(&tempdmap.onmap_script,f))
14642 {
14643 return 0;
14644 }
14645 for(int32_t q = 0; q < 8; ++q)
14646 {
14647 if(!p_igetl(&tempdmap.onmap_initD[q],f))
14648 {
14649 return 0;
14650 }
14651 }
14652 for(int32_t q = 0; q < 8; ++q)
14653 {
14654 for(int32_t w = 0; w < 65; ++w)
14655 {
14656 if(!p_getc(&tempdmap.onmap_initD_label[q][w],f))
14657 {
14658 return 0;
14659 }
14660 }
14661 }
14662 if (!p_igetw(&tempdmap.mirrorDMap, f))
14663 {
14664 return 0;
14665 }
14666 if (!p_igetl(&tempdmap.tmusic_loop_start, f))
14667 {
14668 return 0;
14669 }
14670 if (!p_igetl(&tempdmap.tmusic_loop_end, f))
14671 {
14672 return 0;
14673 }
14674 if (!p_igetl(&tempdmap.tmusic_xfade_in, f))
14675 {
14676 return 0;
14677 }
14678 if (!p_igetl(&tempdmap.tmusic_xfade_out, f))
14679 {
14680 return 0;
14681 }
14682 }
14683 }
14684 DMaps[i].clear();
14685 DMaps[i] = tempdmap;
14686 }
14687
14688 return 1;
14689 }
14690
14691
14692
14693 int32_t writeonedmap(PACKFILE *f, int32_t i)
14694 {
14695
14696 dword section_version=V_DMAPS;
14697 int32_t zversion = ZELDA_VERSION;
14698 int32_t zbuild = VERSION_BUILD;
14699
14700
14701 //section version info
14702 if(!p_iputl(V_ZDMAP,f))
14703 {
14704 return 0;
14705 }
14706 if(!p_iputl(zversion,f))
14707 {
14708 return 0;
14709 }
14710 if(!p_iputl(zbuild,f))
14711 {
14712 return 0;
14713 }
14714 if(!p_iputw(section_version,f))
14715 {
14716 new_return(2);
14717 }
14718
14719 if(!write_deprecated_section_cversion(section_version, f))
14720 {
14721 new_return(3);
14722 }
14723
14724
14725
14726 if(!p_putc(DMaps[i].map,f))
14727 {
14728 new_return(6);
14729 }
14730
14731 if(!p_iputw(DMaps[i].level,f))
14732 {
14733 new_return(7);
14734 }
14735
14736 if(!p_putc(DMaps[i].xoff,f))
14737 {
14738 new_return(8);
14739 }
14740
14741 if(!p_putc(DMaps[i].compass,f))
14742 {
14743 new_return(9);
14744 }
14745
14746 if(!p_iputw(DMaps[i].color,f))
14747 {
14748 new_return(10);
14749 }
14750
14751 if(!p_putc(DMaps[i].midi,f))
14752 {
14753 new_return(11);
14754 }
14755
14756 if(!p_putc(DMaps[i].cont,f))
14757 {
14758 new_return(12);
14759 }
14760
14761 if(!p_putc(DMaps[i].type,f))
14762 {
14763 new_return(13);
14764 }
14765
14766 for(int32_t j=0; j<8; j++)
14767 {
14768 if(!p_putc(DMaps[i].grid[j],f))
14769 {
14770 new_return(14);
14771 }
14772 }
14773
14774 //16
14775 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
14776 {
14777 new_return(15);
14778 }
14779
14780 if(!pfwrite(&DMaps[i].title,sizeof(DMaps[0].title),f))
14781 {
14782 new_return(16);
14783 }
14784
14785 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
14786 {
14787 new_return(17);
14788 }
14789
14790 if(!p_iputl(DMaps[i].minimap_tile[0],f))
14791 {
14792 new_return(18);
14793 }
14794
14795 if(!p_putc(DMaps[i].minimap_cset[0],f))
14796 {
14797 new_return(19);
14798 }
14799
14800 if(!p_iputl(DMaps[i].minimap_tile[1],f))
14801 {
14802 new_return(20);
14803 }
14804
14805 if(!p_putc(DMaps[i].minimap_cset[1],f))
14806 {
14807 new_return(21);
14808 }
14809
14810 if(!p_iputl(DMaps[i].largemap_tile[0],f))
14811 {
14812 new_return(22);
14813 }
14814
14815 if(!p_putc(DMaps[i].largemap_cset[0],f))
14816 {
14817 new_return(23);
14818 }
14819
14820 if(!p_iputl(DMaps[i].largemap_tile[1],f))
14821 {
14822 new_return(24);
14823 }
14824
14825 if(!p_putc(DMaps[i].largemap_cset[1],f))
14826 {
14827 new_return(25);
14828 }
14829
14830 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
14831 {
14832 new_return(26);
14833 }
14834
14835 if(!p_putc(DMaps[i].tmusictrack,f))
14836 {
14837 new_return(25);
14838 }
14839
14840 if(!p_putc(DMaps[i].active_subscreen,f))
14841 {
14842 new_return(26);
14843 }
14844
14845 if(!p_putc(DMaps[i].passive_subscreen,f))
14846 {
14847 new_return(27);
14848 }
14849
14850 byte disabled[32];
14851 memset(disabled,0,32);
14852
14853 for(int32_t j=0; j<MAXITEMS; j++)
14854 {
14855 if(DMaps[i].disableditems[j])
14856 {
14857 disabled[j/8] |= (1 << (j%8));
14858 }
14859 }
14860
14861 if(!pfwrite(disabled,32,f))
14862 {
14863 new_return(28);
14864 }
14865
14866 if(!p_iputl(DMaps[i].flags,f))
14867 {
14868 new_return(29);
14869 }
14870 if(!p_putc(DMaps[i].sideview,f))
14871 {
14872 new_return(30);
14873 }
14874 if(!p_iputw(DMaps[i].script,f))
14875 {
14876 new_return(31);
14877 }
14878 for ( int32_t q = 0; q < 8; q++ )
14879 {
14880 if(!p_iputl(DMaps[i].initD[q],f))
14881 {
14882 new_return(32);
14883 }
14884
14885 }
14886 for ( int32_t q = 0; q < 8; q++ )
14887 {
14888 for ( int32_t w = 0; w < 65; w++ )
14889 {
14890 if (!p_putc(DMaps[i].initD_label[q][w],f))
14891 {
14892 new_return(33);
14893 }
14894 }
14895 }
14896 if(!p_iputw(DMaps[i].active_sub_script,f))
14897 {
14898 new_return(34);
14899 }
14900 if(!p_iputw(DMaps[i].passive_sub_script,f))
14901 {
14902 new_return(35);
14903 }
14904 for(int32_t q = 0; q < 8; ++q)
14905 {
14906 if(!p_iputl(DMaps[i].sub_initD[q],f))
14907 {
14908 new_return(36);
14909 }
14910 }
14911 for(int32_t q = 0; q < 8; ++q)
14912 {
14913 for(int32_t w = 0; w < 65; ++w)
14914 {
14915 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
14916 {
14917 new_return(37);
14918 }
14919 }
14920 }
14921 if(!p_iputw(DMaps[i].onmap_script,f))
14922 {
14923 new_return(35);
14924 }
14925 for(int32_t q = 0; q < 8; ++q)
14926 {
14927 if(!p_iputl(DMaps[i].onmap_initD[q],f))
14928 {
14929 new_return(36);
14930 }
14931 }
14932 for(int32_t q = 0; q < 8; ++q)
14933 {
14934 for(int32_t w = 0; w < 65; ++w)
14935 {
14936 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
14937 {
14938 new_return(37);
14939 }
14940 }
14941 }
14942 if (!p_iputw(DMaps[i].mirrorDMap, f))
14943 {
14944 new_return(38);
14945 }
14946 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
14947 {
14948 new_return(39);
14949 }
14950 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
14951 {
14952 new_return(40);
14953 }
14954 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
14955 {
14956 new_return(41);
14957 }
14958 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
14959 {
14960 new_return(42);
14961 }
14962
14963 return 1;
14964 }
14965
14966
14967 int32_t readonedmap(PACKFILE *f, int32_t index)
14968 {
14969 dword section_version = 0;
14970 int32_t zversion = 0;
14971 int32_t zbuild = 0;
14972 dmap tempdmap{};
14973 int32_t datatype_version = 0;
14974 int32_t first = 0;
14975 int32_t last = 0;
14976 int32_t max = 0;
14977 int32_t count = 0;
14978
14979 //char dmapstring[64]={0};
14980 //section version info
14981 if(!p_igetl(&datatype_version,f))
14982 {
14983 return 0;
14984 }
14985 if ( datatype_version < 0 )
14986 {
14987 if(!p_igetl(&zversion,f))
14988 {
14989 return 0;
14990 }
14991 }
14992 else
14993 {
14994 zversion = datatype_version;
14995 }
14996 if(!p_igetl(&zbuild,f))
14997 {
14998 return 0;
14999 }
15000
15001 if(!p_igetw(&section_version,f))
15002 {
15003 return 0;
15004 }
15005
15006 if(!read_deprecated_section_cversion(f))
15007 {
15008 return 0;
15009 }
15010 al_trace("readonedmap section_version: %d\n", section_version);
15011
15012
15013 if ( datatype_version < 0 )
15014 {
15015 if(!p_igetl(&max,f))
15016 {
15017 return 0;
15018 }
15019 if(!p_igetl(&first,f))
15020 {
15021 return 0;
15022 }
15023 if(!p_igetl(&last,f))
15024 {
15025 return 0;
15026 }
15027 if(!p_igetl(&count,f))
15028 {
15029 return 0;
15030 }
15031 }
15032 if ( zversion > ZELDA_VERSION )
15033 {
15034 al_trace("Cannot read .zdmap packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
15035 return 0;
15036 }
15037 else if (( section_version > V_DMAPS ))
15038 {
15039 al_trace("Cannot read .zdmap packfile made using V_DMAPS (%d)\n", section_version);
15040 return 0;
15041 }
15042 else
15043 {
15044 al_trace("Reading a .zdmap packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
15045 }
15046 //if(!pfread(&dmapstring, 64, f))
15047 //{
15048 // return 0;
15049 //}
15050
15051
15052
15053
15054 if(!p_getc(&tempdmap.map,f))
15055 {
15056 return 0;
15057 }
15058
15059 if(!p_igetw(&tempdmap.level,f))
15060 {
15061 return 0;
15062 }
15063
15064 if(!p_getc(&tempdmap.xoff,f))
15065 {
15066 return 0;
15067 }
15068
15069 if(!p_getc(&tempdmap.compass,f))
15070 {
15071 return 0;
15072 }
15073
15074 if(!p_igetw(&tempdmap.color,f))
15075 {
15076 return 0;
15077 }
15078
15079 if(!p_getc(&tempdmap.midi,f))
15080 {
15081 return 0;
15082 }
15083
15084 if(!p_getc(&tempdmap.cont,f))
15085 {
15086 return 0;
15087 }
15088
15089 if(!p_getc(&tempdmap.type,f))
15090 {
15091 return 0;
15092 }
15093
15094 for(int32_t j=0; j<8; j++)
15095 {
15096 if(!p_getc(&tempdmap.grid[j],f))
15097 {
15098 return 0;
15099 }
15100 }
15101
15102 //16
15103 if(!pfread(&tempdmap.name,sizeof(DMaps[0].name),f))
15104 {
15105 return 0;
15106 }
15107
15108 if (section_version<20)
15109 {
15110 char title[22];
15111 if (!p_getstr(title, sizeof(title) - 1, f))
15112 {
15113 return 0;
15114 }
15115 tempdmap.title.assign(title);
15116 }
15117 else
15118 {
15119 if (!p_getwstr(&tempdmap.title, f))
15120 {
15121 return 0;
15122 }
15123 }
15124
15125 if(!pfread(&tempdmap.title,sizeof(DMaps[0].title),f))
15126 {
15127 return 0;
15128 }
15129
15130 if(!pfread(&tempdmap.intro,sizeof(DMaps[0].intro),f))
15131 {
15132 return 0;
15133 }
15134
15135 if(!p_igetl(&tempdmap.minimap_tile[0],f))
15136 {
15137 return 0;
15138 }
15139
15140 if(!p_getc(&tempdmap.minimap_cset[0],f))
15141 {
15142 return 0;
15143 }
15144
15145 if(!p_igetl(&tempdmap.minimap_tile[1],f))
15146 {
15147 return 0;
15148 }
15149
15150 if(!p_getc(&tempdmap.minimap_cset[1],f))
15151 {
15152 return 0;
15153 }
15154
15155 if(!p_igetl(&tempdmap.largemap_tile[0],f))
15156 {
15157 return 0;
15158 }
15159
15160 if(!p_getc(&tempdmap.largemap_cset[0],f))
15161 {
15162 return 0;
15163 }
15164
15165 if(!p_igetl(&tempdmap.largemap_tile[1],f))
15166 {
15167 return 0;
15168 }
15169
15170 if(!p_getc(&tempdmap.largemap_cset[1],f))
15171 {
15172 return 0;
15173 }
15174
15175 if(!pfread(&tempdmap.tmusic,sizeof(DMaps[0].tmusic),f))
15176 {
15177 return 0;
15178 }
15179
15180 if(!p_getc(&tempdmap.tmusictrack,f))
15181 {
15182 return 0;
15183 }
15184
15185 if(!p_getc(&tempdmap.active_subscreen,f))
15186 {
15187 return 0;
15188 }
15189
15190 if(!p_getc(&tempdmap.passive_subscreen,f))
15191 {
15192 return 0;
15193 }
15194
15195 byte disabled[32];
15196 memset(disabled,0,32);
15197
15198 if(!pfread(&disabled, 32, f)) return 0;
15199
15200 for(int32_t j=0; j<MAXITEMS; j++)
15201 {
15202 if(disabled[j/8] & (1 << (j%8))) tempdmap.disableditems[j]=1;
15203 else tempdmap.disableditems[j]=0;
15204 }
15205
15206
15207 if(!p_igetl(&tempdmap.flags,f))
15208 {
15209 return 0;
15210 }
15211 if ( zversion >= 0x255 )
15212 {
15213 if ( section_version >= 14 )
15214 {
15215 //2.55 starts here
15216 if(!p_getc(&tempdmap.sideview,f))
15217 {
15218 return 0;
15219 }
15220 if(!p_igetw(&tempdmap.script,f))
15221 {
15222 return 0;
15223 }
15224 for ( int32_t q = 0; q < 8; q++ )
15225 {
15226 if(!p_igetl(&tempdmap.initD[q],f))
15227 {
15228 return 0;
15229 }
15230
15231 }
15232 for ( int32_t q = 0; q < 8; q++ )
15233 {
15234 for ( int32_t w = 0; w < 65; w++ )
15235 {
15236 if (!p_getc(&tempdmap.initD_label[q][w],f))
15237 {
15238 return 0;
15239 }
15240 }
15241 }
15242 if(!p_igetw(&tempdmap.active_sub_script,f))
15243 {
15244 return 0;
15245 }
15246 if(!p_igetw(&tempdmap.passive_sub_script,f))
15247 {
15248 return 0;
15249 }
15250 for(int32_t q = 0; q < 8; ++q)
15251 {
15252 if(!p_igetl(&tempdmap.sub_initD[q],f))
15253 {
15254 return 0;
15255 }
15256 }
15257 for(int32_t q = 0; q < 8; ++q)
15258 {
15259 for(int32_t w = 0; w < 65; ++w)
15260 {
15261 if(!p_getc(&tempdmap.sub_initD_label[q][w],f))
15262 {
15263 return 0;
15264 }
15265 }
15266 }
15267 if(!p_igetw(&tempdmap.onmap_script,f))
15268 {
15269 return 0;
15270 }
15271 for(int32_t q = 0; q < 8; ++q)
15272 {
15273 if(!p_igetl(&tempdmap.onmap_initD[q],f))
15274 {
15275 return 0;
15276 }
15277 }
15278 for(int32_t q = 0; q < 8; ++q)
15279 {
15280 for(int32_t w = 0; w < 65; ++w)
15281 {
15282 if(!p_getc(&tempdmap.onmap_initD_label[q][w],f))
15283 {
15284 return 0;
15285 }
15286 }
15287 }
15288 if (!p_igetw(&tempdmap.mirrorDMap, f))
15289 {
15290 return 0;
15291 }
15292 if (!p_igetl(&tempdmap.tmusic_loop_start, f))
15293 {
15294 return 0;
15295 }
15296 if (!p_igetl(&tempdmap.tmusic_loop_end, f))
15297 {
15298 return 0;
15299 }
15300 if (!p_igetl(&tempdmap.tmusic_xfade_in, f))
15301 {
15302 return 0;
15303 }
15304 if (!p_igetl(&tempdmap.tmusic_xfade_out, f))
15305 {
15306 return 0;
15307 }
15308 }
15309 }
15310 DMaps[index] = tempdmap;
15311
15312 return 1;
15313 }
15314
15315 int32_t onDmaps()
15316 {
15317 DMapListerDialog(0).show();
15318 return D_O_K;
15319 }
15320
15321 int32_t onMaps()
15322 {
15323 call_edit_map_settings(Map.getCurrMap());
15324 return D_O_K;
15325 }
15326
15327 int32_t onMidis()
15328 {
15329 stopMusic();
15330 MidiListerDialog().show();
15331 return D_O_K;
15332 }
15333
15334 static DIALOG editmusic_dlg[] =
15335 {
15336 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15337 { jwin_win_proc, 24, 20, 273, 189, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Music Specs", NULL, NULL },
15338 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15339 // 2
15340 { jwin_text_proc, 56, 94-16, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Music:", NULL, NULL },
15341 { jwin_text_proc, 104, 94-16, 48, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15342 { jwin_text_proc, 56, 114, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
15343 { jwin_edit_proc, 104, 114-4, 160, 16, vc(12), vc(1), 0, 0, 19, 0, NULL, NULL, NULL },
15344 { jwin_text_proc, 56, 124-4+12, 56, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Volume:", NULL, NULL },
15345 { jwin_edit_proc, 120, 124-4+12-4, 32, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
15346 // 8
15347 { jwin_check_proc, 176, 124+12-4, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, (void *) "Loop", NULL, NULL },
15348 // 9
15349 { jwin_button_proc, 50, 72-24, 57, 21, vc(14), vc(1), 'l', D_EXIT, 0, 0, (void *) "&Load", NULL, NULL },
15350 { jwin_iconbutton_proc, 116, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_STOPSQUARE, 0, NULL, NULL, NULL },
15351 { jwin_iconbutton_proc, 156, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT, 0, NULL, NULL, NULL },
15352 { jwin_iconbutton_proc, 196, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT2, 0, NULL, NULL, NULL },
15353 { jwin_iconbutton_proc, 236, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT3, 0, NULL, NULL, NULL },
15354 // 14
15355 { jwin_text_proc, 56, 134+4+12, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start:", NULL, NULL },
15356 { jwin_edit_proc, 112, 134+12, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15357 { jwin_text_proc, 176, 134+12+4, 56, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Loop Start:", NULL, NULL },
15358 { jwin_edit_proc, 240, 134+12, 40, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15359 { jwin_text_proc, 176, 144+12+12, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Loop End:", NULL, NULL },
15360 { jwin_edit_proc, 240, 144+12+12-4, 40, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15361 // 20
15362 { jwin_text_proc, 176, 94-16, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Position:", NULL, NULL },
15363 { jwin_text_proc, 217, 94-16, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15364 { jwin_text_proc, 176, 104-8, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Length:", NULL, NULL },
15365 { jwin_text_proc, 216, 104-8, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15366 { jwin_text_proc, 56, 104-8, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Time:", NULL, NULL },
15367 { jwin_text_proc, 104, 104-8, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15368 // 26
15369 { jwin_button_proc, 90, 160+12+12, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15370 { jwin_button_proc, 170, 160+12+12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15371 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
15372 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15373 };
15374
15375 int32_t d_musiclist_proc(int32_t msg,DIALOG *d,int32_t c)
15376 {
15377 return jwin_list_proc(msg,d,c);
15378 }
15379
15380 12 static ListData enhancedmusic_list(enhancedmusiclist, &font);
15381
15382 static DIALOG selectmusic_dlg[] =
15383 {
15384 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15385 12 { jwin_win_proc, 24, 20, 273, 189, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Enhanced Music", NULL, NULL },
15386 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15387 12 { d_musiclist_proc, 31, 44, 164, (1+16)*8, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &enhancedmusic_list, NULL, NULL },
15388 12 { jwin_button_proc, 90, 160+12+12, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
15389 12 { jwin_button_proc, 170, 160+12+12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
15390 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_DEL, (void *) close_dlg, NULL, NULL },
15391 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15392 };
15393
15394 const char *warptypelist(int32_t index, int32_t *list_size)
15395 {
15396 if(index>=0)
15397 {
15398 if(index>=MAXWARPTYPES)
15399 index=MAXWARPTYPES-1;
15400
15401 return warptype_string[index];
15402 }
15403
15404 *list_size=MAXWARPTYPES;
15405 // *list_size=6;
15406 return NULL;
15407 }
15408
15409 const char *warpeffectlist(int32_t index, int32_t *list_size)
15410 {
15411 if(index>=0)
15412 {
15413 if(index>=MAXWARPEFFECTS)
15414 index=MAXWARPEFFECTS-1;
15415
15416 return warpeffect_string[index];
15417 }
15418
15419 *list_size=MAXWARPEFFECTS;
15420 return NULL;
15421 }
15422
15423 static int32_t warp1_list[] =
15424 {
15425 2,3,4,5,6,7,8,9,10,11,12,13,53,54,63,67,-1
15426 };
15427
15428 static int32_t warp2_list[] =
15429 {
15430 17,18,19,20,21,22,23,24,25,26,27,28,55,56,64,68,-1
15431 };
15432
15433 static int32_t warp3_list[] =
15434 {
15435 29,30,31,32,33,34,35,36,37,38,39,40,57,58,65,69,-1
15436 };
15437
15438 static int32_t warp4_list[] =
15439 {
15440 41,42,43,44,45,46,47,48,49,50,51,52,59,60,66,70,-1
15441 };
15442
15443 static TABPANEL warp_tabs[] =
15444 {
15445 // (text)
15446 { (char *)"A", D_SELECTED, warp1_list, 0, NULL },
15447 { (char *)"B", 0, warp2_list, 0, NULL },
15448 { (char *)"C", 0, warp3_list, 0, NULL },
15449 { (char *)"D", 0, warp4_list, 0, NULL },
15450 { NULL, 0, NULL, 0, NULL }
15451 };
15452
15453 int32_t onTileWarpIndex(int32_t index)
15454 {
15455 int32_t i=-1;
15456
15457 while(warp_tabs[++i].text != NULL)
15458 warp_tabs[i].flags = (i==index ? D_SELECTED : 0);
15459
15460 onTileWarp();
15461 return D_O_K;
15462 }
15463
15464 static char warpr_buf[10];
15465 const char *warprlist(int32_t index, int32_t *list_size)
15466 {
15467 if(index>=0)
15468 {
15469 bound(index,0,3);
15470 sprintf(warpr_buf,"%c",index+0x41);
15471 return warpr_buf;
15472 }
15473
15474 *list_size=4;
15475 return NULL;
15476 }
15477
15478 int32_t d_wflag_proc(int32_t msg,DIALOG *d,int32_t c);
15479
15480 12 static ListData warp_dlg_list(warptypelist, &font);
15481 12 static ListData warp_ret_list(warprlist, &font);
15482
15483 int32_t d_warpdestscrsel_proc(int32_t msg,DIALOG *d,int32_t c)
15484 {
15485 if(msg == MSG_START)
15486 {
15487 d->d1 = -1; //cached val
15488 d->d2 = -1; //cached dmap
15489 d->fg = 0; //cached 'force_16'
15490 }
15491 char* buf = (char*)d->dp;
15492 vector<DIALOG*>* dlgs = (vector<DIALOG*>*)d->dp2;
15493 int* dmap_ptr = (int*) d->dp3;
15494 if(!(buf && dmap_ptr))
15495 return D_O_K;
15496 bool is_overworld = ((DMaps[*dmap_ptr].type&dmfTYPE)==dmOVERW);
15497 int scrw = is_overworld ? 16 : 8, scrh = 9;
15498 const int max = 0x87;
15499 int bufval = zc_xtoi(buf);
15500 int val = vbound(bufval,0,max);
15501 auto& dm = DMaps[*dmap_ptr];
15502 auto val_offset = dm.xoff < 0 ? -dm.xoff : 0;
15503 bool force_16 = d->fg;
15504 if(!is_overworld)
15505 {
15506 if((val&0xF) >= 0x8)
15507 force_16 = true;
15508 else if((val&0xF) < val_offset && (val&0xF0) < 0x80)
15509 force_16 = true;
15510 }
15511 if(force_16) //can't bound, some quests need to warp out of bounds... -Em
15512 {
15513 scrw = 16; //just force show the larger grid instead
15514 val_offset = 0;
15515 }
15516
15517 int xscl = d->w/scrw;
15518 int yscl = d->h/scrh;
15519
15520 int ret = D_O_K;
15521 bool redraw = false;
15522 if(d->d1 != val)
15523 {
15524 redraw = true;
15525 d->d1 = val;
15526 }
15527 if(bufval != val)
15528 {
15529 redraw = true;
15530 sprintf(buf, "%X", val);
15531 }
15532 if(d->d2 != *dmap_ptr)
15533 {
15534 redraw = true;
15535 d->d2 = *dmap_ptr;
15536 }
15537 switch(msg)
15538 {
15539 case MSG_WANTFOCUS:
15540 ret = D_WANTFOCUS;
15541 break;
15542 case MSG_CLICK:
15543 {
15544 d->fg = force_16 ? 1 : 0;
15545 bool redraw2 = false;
15546 while(gui_mouse_b())
15547 {
15548 if(redraw2)
15549 {
15550 broadcast_dialog_message(MSG_DRAW, 0);
15551 redraw2 = false;
15552 }
15553 if(!d->fg && (gui_mouse_b()&2))
15554 {
15555 scrw = 16;
15556 xscl = d->w/scrw;
15557 yscl = d->h/scrh;
15558 val_offset = 0;
15559 d->fg = 1;
15560 redraw2 = true;
15561 }
15562 custom_vsync();
15563 if(!mouse_in_rect(d->x,d->y,d->w,d->h))
15564 continue;
15565 int mx = gui_mouse_x()-d->x, my = gui_mouse_y()-d->y;
15566 int y = vbound(my/yscl,0,scrh-1);
15567 auto offs = y==8 ? 0 : val_offset;
15568 int x = vbound(mx/xscl,offs,scrw-1);
15569 auto val2 = (y*16)+x;
15570 if(val2 > max) //out of bounds in the bottom-right
15571 continue;
15572 val = val2;
15573 if(d->d1 != val)
15574 {
15575 d->d1 = val;
15576 sprintf(buf, "%02X", val);
15577 redraw2 = true;
15578 }
15579 }
15580 redraw = true;
15581 d->fg = 0;
15582 break;
15583 }
15584 case MSG_DRAW:
15585 {
15586 rectfill(screen,d->x,d->y,d->x+d->w-1,d->y+d->h-1,jwin_pal[jcBOX]);
15587 jwin_draw_frame(screen, d->x-2, d->y-2, d->w+4, d->h+4, FR_MENU);
15588 for(int yind = 0; yind < scrh; ++yind)
15589 {
15590 auto gr = (yind < 8 ? dm.grid[yind] : 0);
15591 for(int xind = (yind == 8 ? 0 : val_offset); xind < scrw; ++xind)
15592 {
15593 int screen_index = xind+(yind*16);
15594 if(screen_index > max)
15595 continue;
15596 int fr = FR_MENU;
15597 if(screen_index == d->d1)
15598 fr = FR_GREEN;
15599 else if(!is_overworld && xind < 8 && (gr&(1<<(8-xind-1))))
15600 fr = FR_MENU_INV;
15601 jwin_draw_frame(screen, d->x+(xind*xscl), d->y+(yind*yscl), xscl, yscl, fr);
15602 }
15603 }
15604 break;
15605 }
15606 case MSG_XCHAR:
15607 {
15608 bool on_80 = (val&0xF0) == 0x80;
15609 switch(c>>8)
15610 {
15611 case KEY_UP:
15612 if((val&0xF0) && !(val_offset && on_80 && (val&0xF) < val_offset))
15613 {
15614 val -= 0x10;
15615 redraw = true;
15616 }
15617 ret |= D_USED_CHAR;
15618 break;
15619 case KEY_DOWN:
15620 if((val&0xF0) < ((val&0xF) < 0x8 ? 0x80 : 0x70))
15621 {
15622 val += 0x10;
15623 redraw = true;
15624 }
15625 ret |= D_USED_CHAR;
15626 break;
15627 case KEY_LEFT:
15628 if((val&0xF) > (on_80 ? 0 : val_offset))
15629 {
15630 --val;
15631 redraw = true;
15632 }
15633 ret |= D_USED_CHAR;
15634 break;
15635 case KEY_RIGHT:
15636 if((val&0xF) < scrw-1 && val < 0x87)
15637 {
15638 ++val;
15639 redraw = true;
15640 }
15641 ret |= D_USED_CHAR;
15642 break;
15643 }
15644 if(redraw)
15645 sprintf(buf, "%02X", val);
15646 break;
15647 }
15648 }
15649 if(redraw)
15650 {
15651 if(msg == MSG_IDLE)
15652 broadcast_dialog_message(MSG_DRAW,0);
15653 else
15654 {
15655 d->d1 = d->d2 = -1;
15656 object_message(d,MSG_IDLE,0);
15657 }
15658 }
15659
15660 return ret;
15661 }
15662
15663 int32_t tilewarpdmapxy[6] = {170,38,170,18,170,27};
15664 static DIALOG tilewarp_dlg[] =
15665 {
15666 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15667 12 { jwin_win_proc, 0, 0, 302, 178, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15668 12 { jwin_rtext_proc, 89, 43, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Type:", NULL, NULL },
15669 12 { jwin_rtext_proc, 57, 62, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15670 12 { jwin_rtext_proc, 57, 80, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15671 12 { jwin_droplist_proc, 91, 38, 193, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_dlg_list, NULL, NULL },
15672 //5
15673 12 { d_dropdmaplist_proc, 59, 57, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, tilewarpdmapxy },
15674 12 { jwin_hexedit_proc, 59, 76, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15675 12 { jwin_button_proc, 61, 152, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15676 12 { jwin_button_proc, 121, 152, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15677 12 { jwin_button_proc, 181, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15678 //10
15679 12 { jwin_rtext_proc, 82, 95, 100, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Use Warp Return:", NULL, NULL },
15680 12 { jwin_droplist_proc, 10, 105, 72, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_ret_list, NULL, NULL },
15681 12 { jwin_check_proc, 10, 125, 129, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Combos Carry Over", NULL, NULL },
15682 12 { d_warpdestscrsel_proc, 90, 76, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15683 12 { jwin_button_proc, 59, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "A", NULL, NULL },
15684 //15
15685 12 { jwin_button_proc, 109, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "B", NULL, NULL },
15686 12 { jwin_button_proc, 159, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "C", NULL, NULL },
15687 12 { jwin_button_proc, 209, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "D", NULL, NULL },
15688 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15689 };
15690
15691 int32_t sidewarpdmapxy[6] = {170,38,170,18,170,27};
15692 static DIALOG sidewarp_dlg[] =
15693 {
15694 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15695 12 { jwin_win_proc, 0, 0, 302, 178, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15696 12 { jwin_rtext_proc, 89, 43, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Type:", NULL, NULL },
15697 12 { jwin_rtext_proc, 57, 62, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15698 12 { jwin_rtext_proc, 57, 80, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15699 12 { jwin_droplist_proc, 91, 38, 193, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_dlg_list, NULL, NULL },
15700 //5
15701 12 { d_dropdmaplist_proc, 59, 57, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, tilewarpdmapxy },
15702 12 { jwin_hexedit_proc, 59, 76, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15703 12 { jwin_button_proc, 61, 152, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15704 12 { jwin_button_proc, 121, 152, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15705 12 { jwin_button_proc, 181, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15706 //10
15707 12 { jwin_rtext_proc, 82, 95, 100, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Use Warp Return:", NULL, NULL },
15708 12 { jwin_droplist_proc, 10, 105, 72, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_ret_list, NULL, NULL },
15709 12 { jwin_check_proc, 10, 125, 129, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Combos Carry Over", NULL, NULL },
15710 12 { d_warpdestscrsel_proc, 90, 76, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15711 12 { jwin_button_proc, 59, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "A", NULL, NULL },
15712 //15
15713 12 { jwin_button_proc, 109, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "B", NULL, NULL },
15714 12 { jwin_button_proc, 159, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "C", NULL, NULL },
15715 12 { jwin_button_proc, 209, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "D", NULL, NULL },
15716 // 18
15717 12 { d_wflag_proc, 18, 17, 15, 8, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15718 12 { d_wflag_proc, 18, 47, 15, 8, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15719 // 20
15720 12 { d_wflag_proc, 8, 27, 8, 15, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15721 12 { d_wflag_proc, 37, 27, 8, 15, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15722
15723 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15724 };
15725
15726 int32_t warpringxy[6] = {170,38,170,18,170,27};
15727 static DIALOG warpring_warp_dlg[] =
15728 {
15729 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15730 12 { jwin_win_proc, 0, 0, 302, 145, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15731 12 { jwin_rtext_proc, 57, 25, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15732 12 { jwin_rtext_proc, 57, 46, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15733 12 { d_dropdmaplist_proc, 59, 19, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, warpringxy },
15734 12 { jwin_hexedit_proc, 59, 39, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15735 // 5
15736 12 { jwin_button_proc, 61, 115, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15737 12 { jwin_button_proc, 121, 115, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15738 12 { jwin_button_proc, 181, 115, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15739 12 { d_warpdestscrsel_proc, 90, 39, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15740
15741 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15742 };
15743
15744 // Side warp flag procedure
15745 int32_t d_wflag_proc(int32_t msg,DIALOG *d,int32_t)
15746 {
15747 int32_t ret = D_O_K;
15748 switch(msg)
15749 {
15750 case MSG_DRAW:
15751 {
15752 int32_t c2=(d->flags&D_SELECTED)?d->fg:d->bg;
15753
15754 if(d->d1==1)
15755 {
15756 jwin_draw_frame(screen,d->x,d->y,d->w,d->h, FR_DEEP);
15757 rectfill(screen,d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,c2);
15758
15759 if(d->flags&D_SELECTED)
15760 {
15761 int32_t e=d->d2&3;
15762
15763 if(d->w>d->h)
15764 textprintf_centre_ex(screen,get_zc_font(font_lfont_l), d->x+(d->w/2),d->y,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15765 else
15766 textprintf_centre_ex(screen,get_zc_font(font_lfont_l), d->x+(d->w/2),d->y+(d->h/2)-4,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15767 }
15768
15769 }
15770 else
15771 {
15772 rectfill(screen,d->x, d->y, d->x+d->w-1, d->y+d->h-1,c2);
15773 }
15774 }
15775 break;
15776
15777 case MSG_CLICK:
15778 {
15779 if(d->flags & D_DISABLED)
15780 return D_O_K;
15781 bool rclick = gui_mouse_b() & 2;
15782 if(d->d1==1)
15783 {
15784 if(!(d->flags&D_SELECTED))
15785 {
15786 d->flags |= D_SELECTED;
15787 d->d2 &= 0x80;
15788 if (rclick)
15789 d->d2 |= 3;
15790 }
15791 else
15792 {
15793 if((d->d2&3) == (rclick?0:3))
15794 {
15795 d->flags ^= D_SELECTED;
15796 d->d2 &= 0x80;
15797 }
15798 else
15799 {
15800 int32_t f = d->d2&3;
15801 d->d2 &= 0x80;
15802 f += rclick ? -1 : 1;
15803 d->d2 |= f;
15804 }
15805 }
15806 }
15807 else
15808 {
15809 d->flags^=D_SELECTED;
15810 }
15811
15812 int32_t c2=(d->flags&D_SELECTED)?d->fg:d->bg;
15813
15814 if(d->d1==1)
15815 {
15816 jwin_draw_frame(screen,d->x,d->y,d->w,d->h, FR_DEEP);
15817 rectfill(screen,d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,c2);
15818
15819 if(d->flags&D_SELECTED)
15820 {
15821 int32_t e=d->d2&3;
15822
15823 if(d->w>d->h)
15824 textprintf_centre_ex(screen,get_zc_font(font_lfont_l),d->x+(d->w/2),d->y,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15825 else
15826 textprintf_centre_ex(screen,get_zc_font(font_lfont_l),d->x+(d->w/2),d->y+(d->h/2)-4,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15827 }
15828 }
15829 else
15830 {
15831 rectfill(screen,d->x, d->y, d->x+d->w-1, d->y+d->h-1,c2);
15832 }
15833
15834
15835 while(gui_mouse_b())
15836 {
15837 /* do nothing */
15838 rest(1);
15839 }
15840 ret = D_REDRAWME;
15841 }
15842 break;
15843 }
15844
15845 return ret;
15846 }
15847
15848 int32_t d_dmapscrsel_proc(int32_t msg,DIALOG *d,int32_t c)
15849 {
15850 //these are here to bypass compiler warnings about unused arguments
15851 c=c;
15852
15853 int32_t ret = D_O_K;
15854
15855 switch(msg)
15856 {
15857 case MSG_CLICK:
15858 sprintf((char*)((d+2)->dp),"%X%X",vbound((gui_mouse_y()-d->y)/4,0,7),vbound((gui_mouse_x()-d->x)/(((DMaps[(d-1)->d1].type&dmfTYPE)==1)?4:8),0,(((DMaps[(d-1)->d1].type&dmfTYPE)==1)?15:7)));
15859 object_message(d+2, MSG_DRAW, 0);
15860 break;
15861 }
15862
15863 return ret;
15864 }
15865
15866 int32_t warpdestsel_x=-1;
15867 int32_t warpdestsel_y=-1;
15868 int32_t warpdestmap=-1;
15869 int32_t warpdestscr=-1;
15870
15871 int32_t jwin_minibutton_proc(int32_t msg,DIALOG *d,int32_t c)
15872 {
15873 switch(msg)
15874 {
15875 case MSG_DRAW:
15876 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, false);
15877 return D_O_K;
15878 break;
15879 }
15880
15881 return jwin_button_proc(msg,d,c);
15882 }
15883
15884 int32_t d_triggerbutton_proc(int32_t msg,DIALOG *d,int32_t c)
15885 {
15886 static BITMAP *dummy=create_bitmap_ex(8, 1, 1);
15887
15888 switch(msg)
15889 {
15890 case MSG_START:
15891 d->w=gui_textout_ln(dummy, font, (uint8_t *)d->dp, 0, 0, jwin_pal[jcMEDDARK], -1, 0)+4;
15892 d->h=text_height(font)+5;
15893 break;
15894
15895 case MSG_GOTFOCUS:
15896 d->flags&=~D_GOTFOCUS;
15897 break;
15898
15899 }
15900
15901 return jwin_minibutton_proc(msg,d,c);
15902 }
15903
15904 int32_t d_alltriggerbutton_proc(int32_t msg,DIALOG *d,int32_t c)
15905 {
15906 DIALOG *temp_d;
15907 int32_t ret=d_triggerbutton_proc(msg,d,c);
15908
15909 switch(msg)
15910 {
15911 case MSG_CLICK:
15912 temp_d=d-1;
15913
15914 while(temp_d->proc==d_triggerbutton_proc)
15915 {
15916 temp_d->flags&=~D_SELECTED;
15917 temp_d->flags|=D_DIRTY;
15918
15919 if(d->flags&D_SELECTED)
15920 {
15921 temp_d->flags|=D_SELECTED;
15922 }
15923
15924 --temp_d;
15925 }
15926
15927 break;
15928 }
15929
15930 return ret;
15931 }
15932
15933 int32_t d_ticsedit_proc(int32_t msg,DIALOG *d,int32_t c)
15934 {
15935 int32_t ret = jwin_edit_proc(msg,d,c);
15936
15937 if(msg==MSG_DRAW)
15938 {
15939 int32_t tics=vbound(atoi((char*)d->dp),0,65535);
15940 sprintf((char*)(d+1)->dp,"%s %s",ticksstr(tics),tics==0?"(No Timed Warp)":" ");
15941 object_message(d+1,MSG_DRAW,c);
15942 }
15943
15944 return ret;
15945 }
15946
15947 12 static ListData warp_effect_list(warpeffectlist,&font);
15948
15949 struct tw_data
15950 {
15951 int twscr[4], twtype[4], twdmap[4], wret[4];
15952 byte oflags;
15953 optional<uint> loaded;
15954
15955 tw_data(mapscr* scr) {load_scr(scr);}
15956 void load_scr(mapscr* scr)
15957 {
15958 oflags = scr->tilewarpoverlayflags;
15959 for(int q = 0; q < 4; ++q)
15960 {
15961 twscr[q] = scr->tilewarpscr[q];
15962 twtype[q] = scr->tilewarptype[q];
15963 twdmap[q] = scr->tilewarpdmap[q];
15964 wret[q] = (scr->warpreturnc >> (2*q))&3;
15965 }
15966 loaded.reset();
15967 }
15968 void save_scr(mapscr* scr)
15969 {
15970 saved=false;
15971 scr->tilewarpoverlayflags = oflags;
15972 scr->warpreturnc = scr->warpreturnc & 0xFF00;
15973 for(int q = 0; q < 4; ++q)
15974 {
15975 scr->tilewarpscr[q] = twscr[q];
15976 scr->tilewarptype[q] = twtype[q];
15977 scr->tilewarpdmap[q] = twdmap[q];
15978 scr->warpreturnc |= wret[q] << (2*q);
15979 }
15980 }
15981
15982 void load(uint ind)
15983 {
15984 if(ind >= 4) return;
15985 loaded = ind;
15986 tilewarp_dlg[4].d1 = twtype[ind];
15987 tilewarp_dlg[5].d1 = twdmap[ind];
15988 char* buf = (char*)tilewarp_dlg[6].dp;
15989 sprintf(buf,"%02X",twscr[ind]);
15990 tilewarp_dlg[11].d1 = wret[ind];
15991 SETFLAG(tilewarp_dlg[12].flags, D_SELECTED, get_bit(&oflags,ind));
15992 for(int q = 0; q < 4; ++q)
15993 SETFLAG(tilewarp_dlg[14+q].flags,(D_SELECTED|D_DISABLED),q==ind);
15994 }
15995 void save(uint ind)
15996 {
15997 if(ind >= 4) return;
15998 twtype[ind] = tilewarp_dlg[4].d1;
15999 twdmap[ind] = tilewarp_dlg[5].d1;
16000 char* buf = (char*)tilewarp_dlg[6].dp;
16001 twscr[ind] = vbound(zc_xtoi(buf),0x00,0x87);
16002 wret[ind] = tilewarp_dlg[11].d1;
16003 set_bit(&oflags, ind, tilewarp_dlg[12].flags & D_SELECTED);
16004 }
16005 void save()
16006 {
16007 if(loaded)
16008 save(*loaded);
16009 }
16010 void swap(uint ind)
16011 {
16012 if(ind >= 4) return;
16013 if(loaded)
16014 {
16015 save(*loaded);
16016 if(*loaded == ind)
16017 return;
16018 }
16019 load(ind);
16020 }
16021 };
16022 int32_t onTileWarp()
16023 {
16024 restore_mouse();
16025 tilewarp_dlg[0].dp=(void *) "Tile Warp";
16026 tilewarp_dlg[0].dp2=get_zc_font(font_lfont);
16027
16028 mapscr* mptr = Map.CurrScr();
16029 char buf[10];
16030 tilewarp_dlg[6].dp=buf;
16031 tilewarp_dlg[13].dp = buf;
16032 tilewarp_dlg[13].dp3 = &tilewarp_dlg[5].d1;
16033
16034 vector<DIALOG*> dlgs;
16035 dlgs.push_back(&tilewarp_dlg[5]);
16036 dlgs.push_back(&tilewarp_dlg[6]);
16037 tilewarp_dlg[13].dp2 = &dlgs;
16038
16039 tw_data data(mptr);
16040 data.load(0);
16041
16042 dmap_list_size=MAXDMAPS;
16043 dmap_list_zero=true;
16044
16045 large_dialog(tilewarp_dlg);
16046
16047 bool running = true;
16048 int ret;
16049 do
16050 {
16051 ret = do_zqdialog(tilewarp_dlg,-1);
16052 switch(ret)
16053 {
16054 // OK, GO
16055 case 7: case 8:
16056 running = false;
16057 data.save();
16058 data.save_scr(mptr);
16059 refresh(rMENU);
16060 break;
16061 //Cancel
16062 case 9:
16063 running = false;
16064 break;
16065 //A,B,C,D
16066 case 14: case 15: case 16: case 17:
16067 data.swap(ret-14);
16068 break;
16069 }
16070 }
16071 while(running);
16072
16073 if(ret==8) //GO
16074 {
16075 int32_t index = *data.loaded;
16076
16077 FlashWarpSquare = -1;
16078 int32_t tm = Map.getCurrMap();
16079 int32_t ts = Map.getCurrScr();
16080 int32_t thistype = mptr->tilewarptype[index];
16081 Map.dowarp(0,index);
16082
16083 if((ts!=Map.getCurrScr() || tm!=Map.getCurrMap()) && thistype != wtCAVE && thistype != wtSCROLL)
16084 {
16085 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(index*2))&3;
16086 FlashWarpClk = 32;
16087 }
16088
16089 refresh(rALL);
16090 }
16091
16092 return D_O_K;
16093 }
16094
16095 struct sw_data
16096 {
16097 int swscr[4], swtype[4], swdmap[4], wret[4];
16098 byte oflags;
16099 optional<uint> loaded;
16100
16101 sw_data(mapscr* scr) {load_scr(scr);}
16102 void load_scr(mapscr* scr)
16103 {
16104 oflags = scr->sidewarpoverlayflags;
16105 for(int q = 0; q < 4; ++q)
16106 {
16107 swscr[q] = scr->sidewarpscr[q];
16108 swtype[q] = scr->sidewarptype[q];
16109 swdmap[q] = scr->sidewarpdmap[q];
16110 wret[q] = (scr->warpreturnc >> (2*(q+4)))&3;
16111 }
16112 loaded.reset();
16113
16114 for(int32_t i=0; i<4; i++)
16115 {
16116 sidewarp_dlg[18+i].d2 = 0x80;
16117 if(scr->flags2&(1<<i))
16118 {
16119 sidewarp_dlg[18+i].flags = D_SELECTED ;
16120 sidewarp_dlg[18+i].d2 |= (scr->sidewarpindex>>(2*i))&3;
16121 }
16122 else
16123 {
16124 sidewarp_dlg[18+i].flags = 0;
16125 }
16126 }
16127 }
16128 void save_scr(mapscr* scr)
16129 {
16130 saved=false;
16131 scr->sidewarpoverlayflags = oflags;
16132 scr->warpreturnc = scr->warpreturnc & 0x00FF;
16133 for(int q = 0; q < 4; ++q)
16134 {
16135 scr->sidewarpscr[q] = swscr[q];
16136 scr->sidewarptype[q] = swtype[q];
16137 scr->sidewarpdmap[q] = swdmap[q];
16138 scr->warpreturnc |= wret[q] << (2*(q+4));
16139 }
16140
16141 scr->flags2 &= ~0xF;
16142 scr->sidewarpindex = 0;
16143 for(int32_t i=0; i<4; i++)
16144 {
16145 if(sidewarp_dlg[18+i].flags & D_SELECTED)
16146 scr->flags2 |= 1<<i;
16147 scr->sidewarpindex |= (sidewarp_dlg[18+i].d2&3) << (i*2);
16148 }
16149 }
16150
16151 void load(uint ind)
16152 {
16153 if(ind >= 4) return;
16154 loaded = ind;
16155 sidewarp_dlg[4].d1 = swtype[ind];
16156 sidewarp_dlg[5].d1 = swdmap[ind];
16157 char* buf = (char*)sidewarp_dlg[6].dp;
16158 sprintf(buf,"%02X",swscr[ind]);
16159 sidewarp_dlg[11].d1 = wret[ind];
16160 SETFLAG(sidewarp_dlg[12].flags, D_SELECTED, get_bit(&oflags,ind));
16161 for(int q = 0; q < 4; ++q)
16162 SETFLAG(sidewarp_dlg[14+q].flags,(D_SELECTED|D_DISABLED),q==ind);
16163 }
16164 void save(uint ind)
16165 {
16166 if(ind >= 4) return;
16167 swtype[ind] = sidewarp_dlg[4].d1;
16168 swdmap[ind] = sidewarp_dlg[5].d1;
16169 char* buf = (char*)sidewarp_dlg[6].dp;
16170 swscr[ind] = vbound(zc_xtoi(buf),0x00,0x87);
16171 wret[ind] = sidewarp_dlg[11].d1;
16172 set_bit(&oflags, ind, sidewarp_dlg[12].flags & D_SELECTED);
16173 }
16174 void save()
16175 {
16176 if(loaded)
16177 save(*loaded);
16178 }
16179 void swap(uint ind)
16180 {
16181 if(ind >= 4) return;
16182 if(loaded)
16183 {
16184 save(*loaded);
16185 if(*loaded == ind)
16186 return;
16187 }
16188 load(ind);
16189 }
16190 };
16191 int32_t onSideWarp()
16192 {
16193 restore_mouse();
16194 sidewarp_dlg[0].dp=(void *) "Side Warp";
16195 sidewarp_dlg[0].dp2=get_zc_font(font_lfont);
16196
16197 mapscr* mptr = Map.CurrScr();
16198 char buf[10];
16199 sidewarp_dlg[6].dp=buf;
16200 sidewarp_dlg[13].dp = buf;
16201 sidewarp_dlg[13].dp3 = &sidewarp_dlg[5].d1;
16202
16203 vector<DIALOG*> dlgs;
16204 dlgs.push_back(&sidewarp_dlg[5]);
16205 dlgs.push_back(&sidewarp_dlg[6]);
16206 sidewarp_dlg[13].dp2 = &dlgs;
16207
16208 sw_data data(mptr);
16209 data.load(0);
16210
16211 dmap_list_size=MAXDMAPS;
16212 dmap_list_zero=true;
16213
16214 large_dialog(sidewarp_dlg);
16215
16216 bool running = true;
16217 int ret;
16218 do
16219 {
16220 ret = do_zqdialog(sidewarp_dlg,-1);
16221 switch(ret)
16222 {
16223 // OK, GO
16224 case 7: case 8:
16225 running = false;
16226 data.save();
16227 data.save_scr(mptr);
16228 refresh(rMENU);
16229 break;
16230 //Cancel
16231 case 9:
16232 running = false;
16233 break;
16234 //A,B,C,D
16235 case 14: case 15: case 16: case 17:
16236 data.swap(ret-14);
16237 break;
16238 }
16239 }
16240 while(running);
16241
16242 if(ret==8) //GO
16243 {
16244 int32_t index = *data.loaded;
16245
16246 FlashWarpSquare = -1;
16247 int32_t tm = Map.getCurrMap();
16248 int32_t ts = Map.getCurrScr();
16249
16250 int32_t thistype = mptr->sidewarptype[index];
16251 Map.dowarp(1,index);
16252
16253 if((ts!=Map.getCurrScr() || tm!=Map.getCurrMap()) && thistype != wtSCROLL)
16254 {
16255 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(8+index*2))&3;
16256 FlashWarpClk = 0x20;
16257 }
16258
16259 refresh(rALL);
16260 }
16261
16262 return D_O_K;
16263 }
16264
16265
16266
16267 const char *dirlist(int32_t index, int32_t *list_size)
16268 {
16269 if(index>=0)
16270 {
16271 if(index>3)
16272 index=3;
16273
16274 return mazedirstr[index];
16275 }
16276
16277 *list_size=4;
16278 return NULL;
16279 }
16280
16281 12 static ListData path_dlg_list(dirlist, &font);
16282
16283 static const char *wipestr[] = {"None", "Circle", "Oval", "Triangle", "SMAS", "Fade Black"};
16284 // enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
16285 const char *wipelist(int32_t index, int32_t *list_size)
16286 {
16287 if(index>=0)
16288 {
16289 if(index>5)
16290 index=5;
16291
16292 return wipestr[index];
16293 }
16294
16295 *list_size=6;
16296 return NULL;
16297 }
16298
16299 12 static ListData wipe_effect_dlg_list(wipelist, &font);
16300
16301 static DIALOG path_dlg[] =
16302 {
16303 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
16304 12 { jwin_win_proc, 80, 57, 161, 182, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Maze Path", NULL, NULL },
16305 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16306 12 { jwin_text_proc, 94, 106, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16307 12 { jwin_text_proc, 94, 124, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16308 12 { jwin_text_proc, 94, 142, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16309 12 { jwin_text_proc, 94, 160, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "4th", NULL, NULL },
16310 12 { jwin_text_proc, 94, 178, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Exit", NULL, NULL },
16311 12 { jwin_text_proc, 94, 196, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Wipe effect", NULL, NULL },
16312 12 { jwin_droplist_proc, 140, 102, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16313 12 { jwin_droplist_proc, 140, 120, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16314 12 { jwin_droplist_proc, 140, 138, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16315 12 { jwin_droplist_proc, 140, 156, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16316 12 { jwin_droplist_proc, 140, 174, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16317 12 { jwin_droplist_proc, 140, 192, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &wipe_effect_dlg_list, NULL, NULL },
16318 12 { jwin_button_proc, 90, 212, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16319 12 { jwin_button_proc, 170, 212, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16320 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
16321 12 { jwin_text_proc, 87, 82, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "A Lost Woods-style maze screen", NULL, NULL },
16322 12 { jwin_text_proc, 87, 92, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "with a normal and secret exit.", NULL, NULL },
16323 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16324 };
16325
16326 int32_t onPath()
16327 {
16328 restore_mouse();
16329 path_dlg[0].dp2=get_zc_font(font_lfont);
16330
16331 for(int32_t i=0; i<4; i++)
16332 path_dlg[i+8].d1 = Map.CurrScr()->path[i];
16333
16334 path_dlg[12].d1 = Map.CurrScr()->exitdir;
16335 path_dlg[13].d1 = Map.CurrScr()->maze_transition_wipe;
16336
16337 large_dialog(path_dlg);
16338
16339 int32_t ret;
16340
16341 do
16342 {
16343 ret=do_zqdialog(path_dlg,8);
16344
16345 if(ret==14)
16346 {
16347 for(int32_t i=0; i<4; i++)
16348 {
16349 if(path_dlg[i+8].d1 == path_dlg[12].d1)
16350 {
16351 if(jwin_alert("Exit Problem","One of the path's directions is","also the normal Exit direction! Continue?",NULL,"Yes","No",'y','n',get_zc_font(font_lfont))==2)
16352 ret = -1;
16353
16354 break;
16355 }
16356 }
16357 }
16358 }
16359 while(ret == -1);
16360
16361 if(ret==14)
16362 {
16363 saved=false;
16364
16365 for(int32_t i=0; i<4; i++)
16366 Map.CurrScr()->path[i] = path_dlg[i+8].d1;
16367
16368 Map.CurrScr()->exitdir = path_dlg[12].d1;
16369 Map.CurrScr()->maze_transition_wipe = path_dlg[13].d1;
16370
16371 if(!(Map.CurrScr()->flags&fMAZE))
16372 if(jwin_alert("Screen Flag","Turn on the 'Use Maze Path' Screen Flag?","(Go to 'Screen Data' to turn it off.)",NULL,"Yes","No",'y','n',get_zc_font(font_lfont))==1)
16373 Map.CurrScr()->flags |= fMAZE;
16374 }
16375
16376 refresh(rMAP+rMENU);
16377 return D_O_K;
16378 }
16379
16380
16381
16382 static DIALOG editinfo_dlg[] =
16383 {
16384 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16385 12 { jwin_win_proc, 0, 10, 208, 204, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16386 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16387 12 { jwin_text_proc, 24, 60, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16388 12 { jwin_text_proc, 24, 106, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16389 12 { jwin_text_proc, 24, 152, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16390 12 { jwin_text_proc, 56, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16391 12 { jwin_text_proc, 56, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16392 12 { jwin_text_proc, 56, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16393 // 8
16394 12 { jwin_edit_proc, 86, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16395 12 { d_ndroplist_proc, 56, 74, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16396 12 { jwin_edit_proc, 86, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16397 12 { d_ndroplist_proc, 56, 120, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16398 12 { jwin_edit_proc, 86, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16399 12 { d_ndroplist_proc, 56, 166, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16400 12 { jwin_text_proc, 24, 42, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16401 12 { jwin_edit_proc, 56, 38, 137, 16, vc(12), vc(1), 0, 0, 31, 0, NULL, NULL, NULL },
16402 // 16
16403 12 { jwin_button_proc, 34, 188, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16404 12 { jwin_button_proc, 114, 188, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16405 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16406 };
16407
16408 void EditInfoType(int32_t index)
16409 {
16410 char ps1[6],ps2[6],ps3[6];
16411 char infoname[33];
16412 char caption[40];
16413
16414 int32_t str1, str2, str3;
16415
16416 sprintf(caption,"Info Data %d",index);
16417 editinfo_dlg[0].dp = caption;
16418 editinfo_dlg[0].dp2 = get_zc_font(font_lfont);
16419
16420 sprintf(ps1,"%d",QMisc.info[index].price[0]);
16421 sprintf(ps2,"%d",QMisc.info[index].price[1]);
16422 sprintf(ps3,"%d",QMisc.info[index].price[2]);
16423 strncpy(infoname,QMisc.info[index].name,32);
16424 infoname[32] = 0;
16425 editinfo_dlg[8].dp = ps1;
16426 editinfo_dlg[10].dp = ps2;
16427 editinfo_dlg[12].dp = ps3;
16428 editinfo_dlg[15].dp = infoname;
16429 str1 = QMisc.info[index].str[0];
16430 str2 = QMisc.info[index].str[1];
16431 str3 = QMisc.info[index].str[2];
16432 editinfo_dlg[9].d1 = MsgStrings[str1].listpos;
16433 editinfo_dlg[11].d1 = MsgStrings[str2].listpos;
16434 editinfo_dlg[13].d1 = MsgStrings[str3].listpos;
16435 ListData msgs_list(msgslist2, &a4fonts[font_lfont_l]);
16436 editinfo_dlg[9].dp =
16437 editinfo_dlg[11].dp =
16438 editinfo_dlg[13].dp = (void *) &msgs_list;
16439
16440 large_dialog(editinfo_dlg);
16441
16442 int32_t ret = do_zqdialog(editinfo_dlg,-1);
16443
16444 if(ret==16)
16445 {
16446 saved=false;
16447 QMisc.info[index].price[0] = vbound(atoi(ps1), 0, 65535);
16448 QMisc.info[index].price[1] = vbound(atoi(ps2), 0, 65535);
16449 QMisc.info[index].price[2] = vbound(atoi(ps3), 0, 65535);
16450 strncpy(QMisc.info[index].name,infoname,32);
16451 str1 = editinfo_dlg[9].d1;
16452 str2 = editinfo_dlg[11].d1;
16453 str3 = editinfo_dlg[13].d1;
16454 QMisc.info[index].str[0] = msg_at_pos(str1);
16455 QMisc.info[index].str[1] = msg_at_pos(str2);
16456 QMisc.info[index].str[2] = msg_at_pos(str3);
16457
16458 //move 0s to the end
16459 word swaptmp;
16460
16461 if(QMisc.info[index].str[0] == 0)
16462 {
16463 //possibly permute the infos
16464 if(QMisc.info[index].str[1] != 0)
16465 {
16466 //swap
16467 swaptmp = QMisc.info[index].str[0];
16468 QMisc.info[index].str[0] = QMisc.info[index].str[1];
16469 QMisc.info[index].str[1] = swaptmp;
16470 swaptmp = QMisc.info[index].price[0];
16471 QMisc.info[index].price[0] = QMisc.info[index].price[1];
16472 QMisc.info[index].price[1] = swaptmp;
16473 }
16474 else if(QMisc.info[index].str[2] != 0)
16475 {
16476 //move info 0 to 1, 1 to 2, and 2 to 0
16477 swaptmp = QMisc.info[index].str[0];
16478 QMisc.info[index].str[0] = QMisc.info[index].str[2];
16479 QMisc.info[index].str[2] = QMisc.info[index].str[1];
16480 QMisc.info[index].str[1] = swaptmp;
16481 swaptmp = QMisc.info[index].price[0];
16482 QMisc.info[index].price[0] = QMisc.info[index].price[2];
16483 QMisc.info[index].price[2] = QMisc.info[index].price[1];
16484 QMisc.info[index].price[1] = swaptmp;
16485 }
16486 }
16487
16488 if(QMisc.info[index].str[1] == 0 && QMisc.info[index].str[2] != 0)
16489 //swap
16490 {
16491 swaptmp = QMisc.info[index].str[1];
16492 QMisc.info[index].str[1] = QMisc.info[index].str[2];
16493 QMisc.info[index].str[2] = swaptmp;
16494 swaptmp = QMisc.info[index].price[1];
16495 QMisc.info[index].price[1] = QMisc.info[index].price[2];
16496 QMisc.info[index].price[2] = swaptmp;
16497 }
16498 }
16499 }
16500
16501 int32_t onInfoTypes()
16502 {
16503 info_list_size = 256;
16504
16505 int32_t index = select_data("Info Types",0,infolist,"Edit","Done",get_zc_font(font_lfont));
16506
16507 while(index!=-1)
16508 {
16509 EditInfoType(index);
16510
16511 index = select_data("Info Types",index,infolist,"Edit","Done",get_zc_font(font_lfont));
16512 }
16513
16514 return D_O_K;
16515 }
16516
16517
16518
16519 //This dialogie is self-contained, and does not use dialogue control numbers in a separate array to generate its fields.
16520 static DIALOG editshop_dlg[] =
16521 {
16522 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16523 12 { jwin_win_proc, 0, 10, 221, 204, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16524 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16525 12 { jwin_text_proc, 24, 60, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16526 12 { jwin_text_proc, 24, 106, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16527 12 { jwin_text_proc, 24, 152, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16528 12 { jwin_text_proc, 56, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16529 12 { jwin_text_proc, 56, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16530 12 { jwin_text_proc, 56, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16531 // 8
16532 12 { jwin_edit_proc, 86, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16533 12 { d_nidroplist_proc, 56, 74, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16534 12 { jwin_edit_proc, 86, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16535 12 { d_nidroplist_proc, 56, 120, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16536 12 { jwin_edit_proc, 86, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16537 12 { d_nidroplist_proc, 56, 166, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16538 12 { jwin_text_proc, 24, 42, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16539 12 { jwin_edit_proc, 56, 38, 137, 16, vc(12), vc(1), 0, 0, 31, 0, NULL, NULL, NULL },
16540
16541 // 16
16542 12 { jwin_button_proc, 40, 188, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16543 12 { jwin_button_proc, 121, 188, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16544 //18
16545 12 { jwin_text_proc, 130, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16546 12 { jwin_text_proc, 130, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16547 12 { jwin_text_proc, 130, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16548 // 21
16549 12 { jwin_edit_proc, 155, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16550 12 { jwin_edit_proc, 155, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16551 12 { jwin_edit_proc, 155, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16552
16553 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16554 };
16555
16556 void EditShopType(int32_t index)
16557 {
16558
16559 build_bii_list(true);
16560 char ps1[6],ps2[6],ps3[6];
16561 char info1[6],info2[6],info3[6];
16562 char shopname[32];
16563 char caption[40];
16564
16565 sprintf(caption,"Shop Data %d",index);
16566 editshop_dlg[0].dp = caption;
16567 editshop_dlg[0].dp2=get_zc_font(font_lfont);
16568
16569 sprintf(ps1,"%d",QMisc.shop[index].price[0]);
16570 sprintf(ps2,"%d",QMisc.shop[index].price[1]);
16571 sprintf(ps3,"%d",QMisc.shop[index].price[2]);
16572
16573 sprintf(info1,"%d",QMisc.shop[index].str[0]);
16574 sprintf(info2,"%d",QMisc.shop[index].str[1]);
16575 sprintf(info3,"%d",QMisc.shop[index].str[2]);
16576
16577 sprintf(shopname,"%s",QMisc.shop[index].name);
16578 editshop_dlg[8].dp = ps1;
16579 editshop_dlg[10].dp = ps2;
16580 editshop_dlg[12].dp = ps3;
16581 editshop_dlg[15].dp = shopname;
16582
16583 editshop_dlg[21].dp = info1;
16584 editshop_dlg[22].dp = info2;
16585 editshop_dlg[23].dp = info3;
16586
16587 ListData item_list(itemlist_num, &a4fonts[font_lfont_l]);
16588
16589 editshop_dlg[9].dp = (void *) &item_list;
16590 editshop_dlg[11].dp = (void *) &item_list;
16591 editshop_dlg[13].dp = (void *) &item_list;
16592
16593 for(int32_t i=0; i<3; ++i)
16594 {
16595 if(QMisc.shop[index].hasitem[i])
16596 {
16597 for(int32_t j=0; j<bii_cnt; j++)
16598 {
16599 if(bii[j].i == QMisc.shop[index].item[i])
16600 {
16601 editshop_dlg[9+(i<<1)].d1 = j;
16602 }
16603 }
16604 }
16605 else
16606 {
16607 editshop_dlg[9+(i<<1)].d1 = -2;
16608 }
16609 }
16610
16611 large_dialog(editshop_dlg);
16612
16613 int32_t ret = do_zqdialog(editshop_dlg,-1);
16614
16615 if(ret==16)
16616 {
16617 saved=false;
16618 QMisc.shop[index].price[0] = vbound(atoi(ps1), 0, 65535);
16619 QMisc.shop[index].price[1] = vbound(atoi(ps2), 0, 65535);
16620 QMisc.shop[index].price[2] = vbound(atoi(ps3), 0, 65535);
16621
16622 QMisc.shop[index].str[0] = vbound(atoi(info1), 0, 65535);
16623 QMisc.shop[index].str[1] = vbound(atoi(info2), 0, 65535);
16624 QMisc.shop[index].str[2] = vbound(atoi(info3), 0, 65535);
16625
16626 snprintf(QMisc.shop[index].name, 32, "%s",shopname);
16627
16628 for(int32_t i=0; i<3; ++i)
16629 {
16630 if(bii[editshop_dlg[9+(i<<1)].d1].i == -2)
16631 {
16632 QMisc.shop[index].hasitem[i] = 0;
16633 QMisc.shop[index].item[i] = 0;
16634 QMisc.shop[index].price[i] = 0;
16635 }
16636 else
16637 {
16638 QMisc.shop[index].hasitem[i] = 1;
16639 QMisc.shop[index].item[i] = bii[editshop_dlg[9+(i<<1)].d1].i;
16640 }
16641 }
16642
16643 //filter all the 0 items to the end (yeah, bubble sort; sue me)
16644 word swaptmp;
16645
16646 for(int32_t j=0; j<3-1; j++)
16647 {
16648 for(int32_t k=0; k<2-j; k++)
16649 {
16650 if(QMisc.shop[index].hasitem[k]==0)
16651 {
16652 swaptmp = QMisc.shop[index].item[k];
16653 QMisc.shop[index].item[k] = QMisc.shop[index].item[k+1];
16654 QMisc.shop[index].item[k+1] = swaptmp;
16655 swaptmp = QMisc.shop[index].price[k];
16656 QMisc.shop[index].price[k] = QMisc.shop[index].price[k+1];
16657 QMisc.shop[index].price[k+1] = swaptmp;
16658 swaptmp = QMisc.shop[index].hasitem[k];
16659 QMisc.shop[index].hasitem[k] = QMisc.shop[index].item[k+1];
16660 QMisc.shop[index].hasitem[k+1] = swaptmp;
16661 }
16662 }
16663 }
16664 }
16665 }
16666
16667 int32_t onShopTypes()
16668 {
16669 shop_list_size = 256;
16670
16671 int32_t index = select_data("Shop Types",0,shoplist,"Edit","Done",get_zc_font(font_lfont));
16672
16673 while(index!=-1)
16674 {
16675 EditShopType(index);
16676 index = select_data("Shop Types",index,shoplist,"Edit","Done",get_zc_font(font_lfont));
16677 }
16678
16679 return D_O_K;
16680 }
16681
16682 void call_bottle_dlg(int32_t index);
16683 int32_t onBottleTypes()
16684 {
16685 bottle_list_size = 64;
16686 int32_t index = 0;
16687
16688 while(index > -1)
16689 {
16690 index = select_data("Bottle Types", index, bottlelist, "Edit", "Done", get_zc_font(font_lfont));
16691 if(index > -1)
16692 call_bottle_dlg(index);
16693 }
16694
16695 return D_O_K;
16696 }
16697
16698 void call_bottleshop_dlg(int32_t index);
16699 int32_t onBottleShopTypes()
16700 {
16701 bottleshop_list_size = 256;
16702 int32_t index = 0;
16703
16704 while(index > -1)
16705 {
16706 index = select_data("Bottle Shop Types", index, bottleshoplist, "Edit", "Done", get_zc_font(font_lfont));
16707 if(index > -1)
16708 call_bottleshop_dlg(index);
16709 }
16710
16711 return D_O_K;
16712 }
16713
16714
16715 static char item_drop_set_str_buf[70];
16716 int32_t item_drop_set_list_size=MAXITEMDROPSETS;
16717
16718 const char *itemdropsetlist(int32_t index, int32_t *list_size)
16719 {
16720 if(index>=0)
16721 {
16722 bound(index,0,item_drop_set_list_size-1);
16723 sprintf(item_drop_set_str_buf,"%3d: %s",index,item_drop_sets[index].name);
16724 return item_drop_set_str_buf;
16725 }
16726
16727 *list_size=item_drop_set_list_size;
16728 return NULL;
16729 }
16730
16731 int32_t d_itemdropedit_proc(int32_t msg,DIALOG *d,int32_t c);
16732
16733 static int32_t edititemdropset_1_list[] =
16734 {
16735 // dialog control number
16736 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,24,25,26,27,28, -1
16737 };
16738
16739 static int32_t edititemdropset_2_list[] =
16740 {
16741 // dialog control number
16742 12, 13, 29, 30, 31, 32, 33,34,35,36,37,38,39,40,41,42,43, -1
16743 };
16744
16745 static TABPANEL edititemdropset_tabs[] =
16746 {
16747 // (text)
16748 { (char *)" Page 1 ", D_SELECTED, edititemdropset_1_list, 0, NULL },
16749 { (char *)" Page 2 ", 0, edititemdropset_2_list, 0, NULL },
16750 { NULL, 0, NULL, 0, NULL }
16751 };
16752
16753 static DIALOG edititemdropset_dlg[] =
16754 {
16755 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16756 12 { jwin_win_proc, 0, 0, 320, 240, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16757 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16758
16759 // 2
16760 12 { jwin_button_proc, 89, 213, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16761 12 { jwin_button_proc, 169, 213, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16762
16763 // 4
16764 12 { jwin_text_proc, 9, 29, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16765 12 { jwin_edit_proc, 39, 25, 275, 16, vc(12), vc(1), 0, 0, 32, 0, NULL, NULL, NULL },
16766 12 { jwin_text_proc, 9, 47, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Nothing Chance:", NULL, NULL },
16767 12 { d_itemdropedit_proc, 84, 43, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16768
16769 12 { jwin_tab_proc, 4, 65, 312, 143, vc(0), vc(15), 0, 0, 0, 0, (void *) edititemdropset_tabs, NULL, (void *)edititemdropset_dlg },
16770 12 { jwin_text_proc, 114, 43+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16771 // 10
16772 12 { jwin_text_proc, 10, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Chance:", NULL, NULL },
16773 12 { jwin_text_proc, 56, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Item:", NULL, NULL },
16774 12 { jwin_text_proc, 10, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Chance:", NULL, NULL },
16775 12 { jwin_text_proc, 56, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Item:", NULL, NULL },
16776
16777 // 14
16778 12 { d_itemdropedit_proc, 9, 96, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16779 12 { d_idroplist_proc, 55, 96, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16780 12 { jwin_text_proc, 37, 96+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16781 12 { d_itemdropedit_proc, 9, 118, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16782 12 { d_idroplist_proc, 55, 118, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16783 12 { jwin_text_proc, 37, 118+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16784 12 { d_itemdropedit_proc, 9, 140, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16785 12 { d_idroplist_proc, 55, 140, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16786 12 { jwin_text_proc, 37, 140+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16787 12 { d_itemdropedit_proc, 9, 162, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16788 12 { d_idroplist_proc, 55, 162, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16789 12 { jwin_text_proc, 37, 162+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16790 12 { d_itemdropedit_proc, 9, 184, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16791 12 { d_idroplist_proc, 55, 184, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16792 12 { jwin_text_proc, 37, 184+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16793 // 29
16794 12 { d_itemdropedit_proc, 9, 96, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16795 12 { d_idroplist_proc, 55, 96, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16796 12 { jwin_text_proc, 37, 96+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16797 12 { d_itemdropedit_proc, 9, 118, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16798 12 { d_idroplist_proc, 55, 118, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16799 12 { jwin_text_proc, 37, 118+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16800 12 { d_itemdropedit_proc, 9, 140, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16801 12 { d_idroplist_proc, 55, 140, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16802 12 { jwin_text_proc, 37, 140+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16803 12 { d_itemdropedit_proc, 9, 162, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16804 12 { d_idroplist_proc, 55, 162, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16805 12 { jwin_text_proc, 37, 162+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16806 12 { d_itemdropedit_proc, 9, 184, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16807 12 { d_idroplist_proc, 55, 184, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16808 12 { jwin_text_proc, 39, 184+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16809 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16810 };
16811
16812 int32_t d_itemdropedit_proc(int32_t msg,DIALOG *d,int32_t c)
16813 {
16814 int32_t ret = jwin_edit_proc(msg,d,c);
16815
16816 if(msg==MSG_DRAW)
16817 {
16818 int32_t t = atoi((char*)edititemdropset_dlg[7].dp);
16819
16820 for(int32_t i=0; i<10; ++i)
16821 {
16822 t += atoi((char*)edititemdropset_dlg[14+(i*3)].dp);
16823 }
16824
16825 {
16826 int32_t t2 = (int32_t)(100*atoi((char*)edititemdropset_dlg[7].dp) / zc_max(t,1));
16827 sprintf((char*)edititemdropset_dlg[9].dp,"%d%%%s",t2, t2 <= 11 ? " ":"");
16828 object_message(&edititemdropset_dlg[9],MSG_DRAW,c);
16829 }
16830
16831 for(int32_t i=0; i<10; ++i)
16832 {
16833 int32_t t2 = (int32_t)(100*atoi((char*)edititemdropset_dlg[14+(i*3)].dp) / zc_max(t,1));
16834 sprintf((char*)edititemdropset_dlg[16+(i*3)].dp,"%d%%%s",t2, t2 <= 11 ? " ":"");
16835 object_message(&edititemdropset_dlg[16+(i*3)],MSG_DRAW,c);
16836 }
16837
16838 }
16839
16840 return ret;
16841 }
16842
16843 void EditItemDropSet(int32_t index)
16844 {
16845 build_bii_list(true);
16846 char chance[11][10];
16847 char itemdropsetname[64];
16848 char caption[40];
16849 char percent_str[11][5];
16850
16851 sprintf(caption,"Item Drop Set Data %d",index);
16852 edititemdropset_dlg[0].dp = caption;
16853 edititemdropset_dlg[0].dp2=get_zc_font(font_lfont);
16854
16855 sprintf(itemdropsetname,"%s",item_drop_sets[index].name);
16856 edititemdropset_dlg[5].dp = itemdropsetname;
16857
16858 sprintf(chance[0],"%d",item_drop_sets[index].chance[0]);
16859 edititemdropset_dlg[7].dp = chance[0];
16860
16861 ListData item_list(itemlist_num, &a4fonts[font_lfont_l]);
16862 sprintf(percent_str[0]," ");
16863 edititemdropset_dlg[9].dp = percent_str[0];
16864
16865 for(int32_t i=0; i<10; ++i)
16866 {
16867 sprintf(chance[i+1],"%d",item_drop_sets[index].chance[i+1]);
16868 edititemdropset_dlg[14+(i*3)].dp = chance[i+1];
16869 edititemdropset_dlg[15+(i*3)].dp = (void *) &item_list;
16870 sprintf(percent_str[i+1]," ");
16871 edititemdropset_dlg[16+(i*3)].dp = percent_str[i+1];
16872
16873 if(item_drop_sets[index].chance[i+1]==0)
16874 {
16875 edititemdropset_dlg[15+(i*3)].d1 = -2;
16876 }
16877 else
16878 {
16879 for(int32_t j=0; j<bii_cnt; j++)
16880 {
16881 if(bii[j].i == item_drop_sets[index].item[i])
16882 {
16883 edititemdropset_dlg[15+(i*3)].d1 = j;
16884 }
16885 }
16886 }
16887 }
16888
16889 large_dialog(edititemdropset_dlg);
16890
16891 int32_t ret = do_zqdialog(edititemdropset_dlg,-1);
16892
16893 if(ret==2)
16894 {
16895 saved=false;
16896
16897 sprintf(item_drop_sets[index].name,"%s",itemdropsetname);
16898
16899 item_drop_sets[index].chance[0]=atoi(chance[0]);
16900
16901 for(int32_t i=0; i<10; ++i)
16902 {
16903 item_drop_sets[index].chance[i+1]=atoi(chance[i+1]);
16904
16905 if(bii[edititemdropset_dlg[15+(i*3)].d1].i == -2)
16906 {
16907 item_drop_sets[index].chance[i+1]=0;
16908 }
16909 else
16910 {
16911 item_drop_sets[index].item[i] = bii[edititemdropset_dlg[15+(i*3)].d1].i;
16912 }
16913
16914 if(item_drop_sets[index].chance[i+1]==0)
16915 {
16916 item_drop_sets[index].item[i] = 0;
16917 }
16918 }
16919 }
16920 }
16921
16922 9 int32_t count_item_drop_sets()
16923 {
16924 9 int32_t count=0;
16925 9 bool found=false;
16926
16927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2195 times.
2195 for(count=255; (count>0); --count)
16928 {
16929
2/2
✓ Branch 0 taken 2186 times.
✓ Branch 1 taken 24056 times.
26242 for(int32_t i=0; (i<11); ++i)
16930 {
16931
2/2
✓ Branch 0 taken 24047 times.
✓ Branch 1 taken 9 times.
24056 if(item_drop_sets[count].chance[i]!=0)
16932 {
16933 9 found=true;
16934 9 break;
16935 }
16936 24047 }
16937
16938
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2186 times.
2195 if(found)
16939 {
16940 9 break;
16941 }
16942 2186 }
16943
16944 9 return count+1;
16945 }
16946
16947 int32_t onItemDropSets()
16948 {
16949 item_drop_set_list_size = MAXITEMDROPSETS;
16950
16951 int32_t index = select_data("Item Drop Sets",0,itemdropsetlist,"Edit","Done",get_zc_font(font_lfont));
16952
16953 while(index!=-1)
16954 {
16955 EditItemDropSet(index);
16956 index = select_data("Item Drop Sets",index,itemdropsetlist,"Edit","Done",get_zc_font(font_lfont));
16957 }
16958
16959 return D_O_K;
16960 }
16961
16962 int32_t curr_ring = 0;
16963
16964 void EditWarpRingScr(int32_t ring,int32_t index)
16965 {
16966 char caption[40],buf[10];
16967 restore_mouse();
16968
16969 sprintf(caption,"Ring %d Warp %d",ring,index+1);
16970 warpring_warp_dlg[0].dp = (void *)caption;
16971 warpring_warp_dlg[0].dp2=get_zc_font(font_lfont);
16972
16973 sprintf(buf,"%02X",QMisc.warp[ring].scr[index]);
16974 warpring_warp_dlg[3].d1 = QMisc.warp[ring].dmap[index];
16975 warpring_warp_dlg[4].dp = buf;
16976 warpring_warp_dlg[8].dp = buf;
16977 warpring_warp_dlg[8].dp3 = &warpring_warp_dlg[3].d1;
16978
16979 vector<DIALOG*> dlgs;
16980 dlgs.push_back(&warpring_warp_dlg[3]);
16981 dlgs.push_back(&warpring_warp_dlg[4]);
16982 warpring_warp_dlg[8].dp2 = &dlgs;
16983
16984 dmap_list_size=MAXDMAPS;
16985 dmap_list_zero=true;
16986
16987 large_dialog(warpring_warp_dlg);
16988
16989 int32_t ret=do_zqdialog(warpring_warp_dlg,-1);
16990
16991 if(ret==5 || ret==6)
16992 {
16993 saved=false;
16994 QMisc.warp[ring].dmap[index] = warpring_warp_dlg[3].d1;
16995 QMisc.warp[ring].scr[index] = zc_xtoi(buf);
16996 }
16997
16998 if(ret==6)
16999 {
17000 Map.dowarp2(ring,index);
17001 refresh(rALL);
17002 }
17003 }
17004
17005 int32_t d_warplist_proc(int32_t msg,DIALOG *d,int32_t c)
17006 {
17007 if(msg==MSG_DRAW)
17008 {
17009 int32_t *xy = (int32_t*)(d->dp3);
17010 int32_t ring = curr_ring;
17011 int32_t dmap = QMisc.warp[ring].dmap[d->d1];
17012 float temp_scale = 1.5;
17013
17014 drawdmap(dmap);
17015
17016 if(xy[0]||xy[1])
17017 {
17018 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
17019 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
17020 int32_t w = 84;
17021 int32_t h = 52;
17022 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
17023 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
17024 }
17025
17026 if(xy[2]||xy[3])
17027 {
17028 textprintf_ex(screen,font,d->x+int32_t(xy[2]*temp_scale),d->y+int32_t(xy[3]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %d ",DMaps[dmap].map+1);
17029 }
17030
17031 if(xy[4]||xy[5])
17032 {
17033 textprintf_ex(screen,font,d->x+int32_t(xy[4]*temp_scale),d->y+int32_t(xy[5]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level:%2d ",DMaps[dmap].level);
17034 }
17035
17036 if(xy[6]||xy[7])
17037 {
17038 textprintf_ex(screen,font,d->x+int32_t(xy[6]*temp_scale),d->y+int32_t(xy[7]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Scr: 0x%02X ",QMisc.warp[ring].scr[d->d1]);
17039 }
17040 }
17041
17042 return jwin_list_proc(msg,d,c);
17043 }
17044
17045 int32_t d_wclist_proc(int32_t msg,DIALOG *d,int32_t c)
17046 {
17047 int32_t d1 = d->d1;
17048 int32_t ret = jwin_droplist_proc(msg,d,c);
17049 QMisc.warp[curr_ring].size=d->d1+3;
17050
17051 if(d->d1 != d1)
17052 return D_CLOSE;
17053
17054 return ret;
17055 }
17056
17057 const char *wclist(int32_t index, int32_t *list_size)
17058 {
17059 static char buf[2];
17060
17061 if(index>=0)
17062 {
17063 if(index>6)
17064 index=6;
17065
17066 sprintf(buf,"%d",index+3);
17067 return buf;
17068 }
17069
17070 *list_size=7;
17071 return NULL;
17072 }
17073
17074 //int32_t warpringdmapxy[8] = {160,116,160,90,160,102,160,154};
17075 int32_t warpringdmapxy[8] = {80,26,80,0,80,12,80,78};
17076
17077 12 static ListData number_list(numberlist, &font);
17078 12 static ListData wc_list(wclist, &font);
17079
17080 static DIALOG warpring_dlg[] =
17081 {
17082 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
17083 12 { jwin_win_proc, 0, 0, 193, 166, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
17084 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17085 12 { jwin_text_proc, 16, 33, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Count:", NULL, NULL },
17086 12 { d_wclist_proc, 72, 29, 48, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 1, 0, (void *) &wc_list, NULL, NULL },
17087 // 4
17088 12 { d_warplist_proc, 16, 50, 65, 71, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &number_list, NULL, warpringdmapxy },
17089 12 { jwin_button_proc, 26, 140, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
17090 12 { jwin_button_proc, 106, 140, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
17091 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
17092 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17093 };
17094
17095 int32_t select_warp()
17096 {
17097 QMisc.warp[curr_ring].size = vbound(QMisc.warp[curr_ring].size,3,9);
17098 number_list_zero = false;
17099
17100 int32_t ret=4;
17101
17102 large_dialog(warpring_dlg);
17103
17104 do
17105 {
17106 number_list_size = QMisc.warp[curr_ring].size;
17107 warpring_dlg[3].d1 = QMisc.warp[curr_ring].size-3;
17108 ret = do_zqdialog(warpring_dlg,ret);
17109 }
17110 while(ret==3);
17111
17112 if(ret==6 || ret==0)
17113 {
17114 return -1;
17115 }
17116
17117 return warpring_dlg[4].d1;
17118 }
17119
17120 void EditWarpRing(int32_t ring)
17121 {
17122 char buf[40];
17123 sprintf(buf,"Ring %d Warps",ring);
17124 warpring_dlg[0].dp = buf;
17125 warpring_dlg[0].dp2 = get_zc_font(font_lfont);
17126 curr_ring = ring;
17127
17128 int32_t index = select_warp();
17129
17130 while(index!=-1)
17131 {
17132 EditWarpRingScr(ring,index);
17133 index = select_warp();
17134 }
17135 }
17136
17137 int32_t onWarpRings()
17138 {
17139 number_list_size = 9;
17140 number_list_zero = true;
17141
17142 int32_t index = select_data("Warp Rings",0,numberlist,"Edit","Done",get_zc_font(font_lfont));
17143
17144 while(index!=-1)
17145 {
17146 EditWarpRing(index);
17147 number_list_size = 9;
17148 number_list_zero = true;
17149 index = select_data("Warp Rings",index,numberlist,"Edit","Done",get_zc_font(font_lfont));
17150 }
17151
17152 return D_O_K;
17153 }
17154
17155 const char *enemy_viewer(int32_t index, int32_t *list_size)
17156 {
17157 if(index<0)
17158 {
17159 *list_size=10;
17160
17161 return NULL;
17162 }
17163
17164 int32_t guy=Map.CurrScr()->enemy[index];
17165
17166 if (guy == 0) return "(None)";
17167 return guy>=eSTART ? guy_string[guy] : (char *) "(Guy - Do Not Use!)";
17168 }
17169
17170 enemy_struct bie[eMAXGUYS];
17171 enemy_struct ce[100];
17172 int32_t enemy_type=0,bie_cnt=-1,ce_cnt;
17173
17174 enemy_struct big[zqMAXGUYS];
17175 enemy_struct cg[100];
17176 int32_t guy_type=0,big_cnt=-1,cg_cnt;
17177
17178 //Uses old_max_guys[] in zq_misc.cpp to define what are visible if bool hide is set true. -Z
17179 void build_bie_list(bool hide)
17180 {
17181 bie[0].s = (char *)"(None)";
17182 bie[0].i = 0;
17183 bie_cnt=1;
17184
17185 for(int32_t i=1; i<eMAXGUYS; i++)
17186 {
17187 if (i < eSTART) continue; // ignore guys - enemies only!
17188
17189 if(i >= OLDMAXGUYS || old_guy_string[i][strlen(old_guy_string[i])-1]!=' ' || !hide)
17190 {
17191 bie[bie_cnt].s = (char *)guy_string[i];
17192 bie[bie_cnt].i = i;
17193 ++bie_cnt;
17194 }
17195 }
17196
17197 for(int32_t i=1; i<bie_cnt-1; i++) //Start at 1 so '(None)' isn't alphabetized!
17198 {
17199 for(int32_t j=i+1; j<bie_cnt; j++)
17200 {
17201 if(strcmp(bie[i].s,bie[j].s)>0)
17202 {
17203 zc_swap(bie[i],bie[j]);
17204 }
17205 }
17206 }
17207 }
17208
17209 int32_t efrontfacingtile(int32_t id)
17210 {
17211 int32_t anim = get_qr(qr_NEWENEMYTILES)?guysbuf[id].e_anim:guysbuf[id].anim;
17212 int32_t usetile = 0;
17213
17214 switch(anim)
17215 {
17216
17217 case aNONE: break;
17218 case aAQUA:
17219 if(!(get_qr(qr_NEWENEMYTILES) && guysbuf[id].attributes[0]))
17220 break;
17221
17222 case aWALLM:
17223 case aGHOMA:
17224 usetile=1;
17225 break;
17226
17227 //Fallthrough
17228 case a2FRM4DIR:
17229 case aWALK:
17230 usetile=2;
17231 break;
17232
17233 case aLEV:
17234 case a3FRM4DIR:
17235 usetile=3;
17236 break;
17237
17238 case aLANM:
17239 usetile = !(get_qr(qr_NEWENEMYTILES))?0:4;
17240 break;
17241
17242 case aNEWDONGO:
17243 case a4FRM8EYE:
17244 case aNEWWIZZ:
17245 case aARMOS4:
17246 case aNEWTEK:
17247 case aNEWWALLM:
17248 case a4FRM4DIRF:
17249 case a4FRM4DIR:
17250 case a4FRM8DIRF:
17251 case a4FRMPOS8DIR:
17252 case a4FRMPOS8DIRF:
17253 case a4FRMPOS4DIR:
17254 case a4FRMPOS4DIRF:
17255 usetile=4;
17256 break;
17257
17258 case aDONGO:
17259 usetile=6;
17260 break;
17261
17262 case aDONGOBS:
17263 usetile=24;
17264 break;
17265
17266 case aNEWLEV:
17267 usetile=40;
17268 break;
17269
17270 case aNEWZORA:
17271 if(guysbuf[id].type==eeZORA)
17272 usetile=44;
17273
17274 break;
17275
17276 case aGLEEOK:
17277 if(!get_qr(qr_NEWENEMYTILES))
17278 usetile = (guysbuf[id].s_tile - guysbuf[id].tile)+1;
17279 else
17280 usetile = (guysbuf[id].attributes[7]);
17281
17282 break;
17283 }
17284
17285 return zc_max(get_qr(qr_NEWENEMYTILES) ? -guysbuf[id].e_tile
17286 : -guysbuf[id].tile, usetile);
17287 }
17288
17289 int32_t onEnemies()
17290 {
17291 call_screenenemies_dialog();
17292 refresh(rALL);
17293 return D_O_K;
17294 }
17295
17296 char author[65],title[65],password[32];
17297
17298 int32_t d_showedit_proc(int32_t msg,DIALOG *d,int32_t c)
17299 {
17300 int32_t ret = jwin_edit_proc(msg,d,c);
17301
17302 if(msg==MSG_DRAW)
17303 {
17304 (d+1)->proc(MSG_DRAW,d+1,0);
17305 }
17306
17307 return ret;
17308 }
17309
17310 int32_t onHeader()
17311 {
17312 call_header_dlg();
17313 return D_O_K;
17314 }
17315
17316 void call_cheats_dlg();
17317 int32_t onCheats()
17318 {
17319 call_cheats_dlg();
17320 return D_O_K;
17321 }
17322
17323 bool do_x_button(BITMAP *dest, int32_t x, int32_t y)
17324 {
17325 bool over=false;
17326
17327 while(gui_mouse_b())
17328 {
17329 custom_vsync();
17330
17331 if(isinRect(gui_mouse_x(),gui_mouse_y(),x,y,x+15,y+13))
17332 {
17333 if(!over)
17334 {
17335 draw_x_button(dest, x, y, D_SELECTED);
17336 over=true;
17337 }
17338 }
17339 else
17340 {
17341 if(over)
17342 {
17343 draw_x_button(dest, x, y, 0);
17344 over=false;
17345 }
17346 }
17347 }
17348
17349 return over;
17350 }
17351
17352 bool do_question_button(BITMAP *dest, int32_t x, int32_t y)
17353 {
17354 bool over=false;
17355
17356 while(gui_mouse_b())
17357 {
17358 custom_vsync();
17359
17360 if(isinRect(gui_mouse_x(),gui_mouse_y(),x,y,x+15,y+13))
17361 {
17362 if(!over)
17363 {
17364 draw_question_button(dest, x, y, D_SELECTED);
17365 over=true;
17366 }
17367 }
17368 else
17369 {
17370 if(over)
17371 {
17372 draw_question_button(dest, x, y, 0);
17373 over=false;
17374 }
17375 }
17376 }
17377
17378 return over;
17379 }
17380
17381
17382 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
17383 {
17384 return D_O_K;
17385 }
17386
17387 int32_t d_maptile_proc(int32_t msg, DIALOG *d, int32_t)
17388 {
17389 switch(msg)
17390 {
17391 case MSG_CLICK:
17392 if(select_tile(d->d1,d->d2,1,d->fg,true, 0, true))
17393 return D_REDRAW;
17394
17395 case MSG_DRAW:
17396 {
17397 int32_t dw = d->w;
17398 int32_t dh = d->h;
17399
17400 if(d->dp2==(void*)1)
17401 {
17402 dw /= 2;
17403 dh /= 2;
17404 }
17405
17406 BITMAP *buf = create_bitmap_ex(8,dw,dh);
17407
17408 if(buf)
17409 {
17410 clear_bitmap(buf);
17411
17412 for(int32_t y=0; y<dh; y+=16)
17413 for(int32_t x=0; x<dw; x+=16)
17414 {
17415 if(d->d1)
17416 puttile16(buf,d->d1+(y>>4)*20+(x>>4),x,y,d->fg,0);
17417 }
17418
17419 if(d->dp2==(void*)1)
17420 stretch_blit(buf,screen,0,0,dw,dh,d->x-1,d->y-1,dw*2,dh*2);
17421 else
17422 blit(buf,screen,0,0,d->x,d->y,dw,dh);
17423
17424 destroy_bitmap(buf);
17425 }
17426 }
17427 }
17428
17429 return D_O_K;
17430 }
17431
17432 static int32_t last_combo=0;
17433 static int32_t last_cset=0;
17434
3/4
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 98292 times.
✓ Branch 3 taken 12 times.
98304 static combo_alias temp_aliases[MAXCOMBOALIASES];
17435
17436 static char comboa_str_buf[32];
17437
17438 int32_t d_comboalist_proc(int32_t msg,DIALOG *d,int32_t c)
17439 {
17440 int32_t d1 = d->d1;
17441 int32_t ret = jwin_droplist_proc(msg,d,c);
17442 comboa_cnt = d->d1;
17443
17444 if(d1!=d->d1)
17445 {
17446 set_comboaradio(temp_aliases[comboa_cnt].layermask);
17447 return D_REDRAW;
17448 }
17449
17450 return ret;
17451 }
17452
17453 const char *comboalist(int32_t index, int32_t *list_size)
17454 {
17455 if(index>=0)
17456 {
17457 bound(index,0,MAXCOMBOALIASES-1);
17458 sprintf(comboa_str_buf,"%d",index);
17459 return comboa_str_buf;
17460 }
17461
17462 *list_size=MAXCOMBOALIASES;
17463 return NULL;
17464 }
17465
17466 extern int32_t scheme[jcMAX];
17467
17468 int32_t d_comboa_proc(int32_t msg,DIALOG *d,int32_t c)
17469 {
17470 //these are here to bypass compiler warnings about unused arguments
17471 c=c;
17472
17473 combo_alias *combo;
17474 combo = &temp_aliases[comboa_cnt];
17475 int32_t position;
17476 int32_t cur_layer, temp_layer;
17477 int32_t lay_count=0;
17478 int32_t size = 2;
17479
17480 int32_t cx1=(gui_mouse_x()-d->x-(120-(combo->width*8)));
17481 int32_t cy1=(gui_mouse_y()-d->y-(80-(combo->height*8)));
17482 int32_t cx=cx1/(16*size);
17483 int32_t cy=cy1/(16*size);
17484
17485 int32_t co,cs;
17486
17487
17488 switch(msg)
17489 {
17490 case MSG_CLICK:
17491 if((cx>combo->width)||(cx1<0))
17492 return D_O_K;
17493
17494 if((cy>combo->height)||(cy1<0))
17495 return D_O_K;
17496
17497 for(int32_t j=0; j<layer_cnt; j++)
17498 {
17499 if(combo->layermask&(1<<j))
17500 lay_count++;
17501 }
17502
17503 position=(lay_count)*(combo->width+1)*(combo->height+1);
17504 position+=(cy*(combo->width+1))+cx;
17505
17506 if(key[KEY_LSHIFT]||key[KEY_RSHIFT])
17507 {
17508 combo->combos[position] = 0;
17509 combo->csets[position] = 0;
17510
17511 while(gui_mouse_b())
17512 {
17513 /* do nothing */
17514 rest(1);
17515 }
17516
17517 return D_REDRAW;
17518 }
17519
17520 co=combo->combos[position];
17521 cs=combo->csets[position];
17522
17523 if((co==0)||(key[KEY_ZC_LCONTROL]))
17524 {
17525 co=last_combo;
17526 cs=last_cset;
17527 }
17528
17529 if((select_combo_2(co,cs)))
17530 {
17531 last_combo = co;
17532 last_cset = cs;
17533
17534 combo->combos[position]=co;
17535 combo->csets[position]=cs;
17536 }
17537
17538 return D_REDRAW;
17539 break;
17540
17541 case MSG_DRAW:
17542 BITMAP *buf = create_bitmap_ex(8,d->w,d->h);
17543
17544 if(buf)
17545 {
17546 clear_bitmap(buf);
17547
17548 for(int32_t z=0; z<=comboa_lmasktotal(combo->layermask); z++)
17549 {
17550 int32_t k=0;
17551 cur_layer=0;
17552 temp_layer=combo->layermask;
17553
17554 while((temp_layer!=0)&&(k<z))
17555 {
17556 if(temp_layer&1)
17557 {
17558 k++;
17559 }
17560
17561 cur_layer++;
17562 temp_layer = temp_layer>>1;
17563 }
17564
17565 for(int32_t y=0; (y<d->h)&&((y/16)<=combo->height); y+=16)
17566 {
17567 for(int32_t x=0; (x<d->w)&&((x/16)<=combo->width); x+=16)
17568 {
17569 int32_t cpos = (z*(combo->width+1)*(combo->height+1))+(((y/16)*(combo->width+1))+(x/16));
17570
17571 if(combo->combos[cpos])
17572 {
17573 if(!((d-1)->flags&D_SELECTED)||(cur_layer==layer_cnt))
17574 {
17575 if(z==0)
17576 {
17577 puttile16(buf,combobuf[combo->combos[cpos]].tile,x,y,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17578 }
17579 else
17580 {
17581 overtile16(buf,combobuf[combo->combos[cpos]].tile,x,y,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17582 }
17583 }
17584 }
17585 }
17586 }
17587 }
17588
17589 rectfill(screen, d->x-2,d->y-2,d->x+256+2,d->y+176+2,jwin_pal[jcBOX]);
17590 int32_t dx = 120-(combo->width*8)+d->x;
17591 int32_t dy = 80-(combo->height*8)+d->y;
17592 stretch_blit(buf,screen,0,0,(combo->width+1)*16,(combo->height+1)*16,dx,dy,(combo->width+1)*16*size,(combo->height+1)*16*size);
17593 //blit(buf,screen,0,0,120-(combo->width*8)+d->x,80-(combo->height*8)+d->y,(combo->width+1)*16,(combo->height+1)*16);
17594 (d-11)->w = (combo->width+1)*16*size+2;
17595 (d-11)->h = (combo->height+1)*16*size+2;
17596 (d-11)->x = 120-(combo->width*8)+4*size+2+(d-14)->x;
17597 (d-11)->y = 80-(combo->height*8)+25*size+2+(d-14)->y;
17598 object_message((d-11),MSG_DRAW,0);
17599
17600 destroy_bitmap(buf);
17601 }
17602
17603 break;
17604 }
17605
17606 return D_O_K;
17607 }
17608
17609 void draw_combo_alias_thumbnail(BITMAP *dest, combo_alias const* combo, int32_t x, int32_t y, int32_t size)
17610 {
17611 if(!combo->combo)
17612 {
17613 int32_t cur_layer, temp_layer;
17614
17615 int32_t cw=combo->width+1;
17616 int32_t ch=combo->height+1;
17617 int32_t dw=cw<<4;
17618 int32_t dh=ch<<4;
17619 int32_t sw=16, sh=16, sx=0, sy=0;
17620
17621 if(cw<ch)
17622 {
17623 sw=((cw<<4)/ch);
17624 sx=((16-sw)>>1);
17625 }
17626 else
17627 {
17628 sh=((ch<<4)/cw);
17629 sy=((16-sh)>>1);
17630 }
17631
17632 BITMAP *buf = create_bitmap_ex(8,dw,dh);
17633 BITMAP *buf2 = create_bitmap_ex(8, 16*size, 16*size);
17634 clear_bitmap(buf);
17635 clear_bitmap(buf2);
17636
17637 if(buf&&(combo->width>0||combo->height>0||combo->combos[0]>0))
17638 {
17639 clear_bitmap(buf);
17640
17641 for(int32_t z=0; z<=comboa_lmasktotal(combo->layermask); z++)
17642 {
17643 int32_t k=0;
17644 cur_layer=0;
17645 temp_layer=combo->layermask;
17646
17647 while((temp_layer!=0)&&(k<z))
17648 {
17649 if(temp_layer&1)
17650 {
17651 k++;
17652 }
17653
17654 cur_layer++;
17655 temp_layer = temp_layer>>1;
17656 }
17657
17658 for(int32_t y2=0; (y2<dh)&&((y2>>4)<=combo->height); y2+=16)
17659 {
17660 for(int32_t x2=0; (x2<dw)&&((x2>>4)<=combo->width); x2+=16)
17661 {
17662 int32_t cpos = (z*(combo->width+1)*(combo->height+1))+(((y2/16)*(combo->width+1))+(x2/16));
17663
17664 if(combo->combos[cpos])
17665 {
17666 if(z==0)
17667 {
17668 puttile16(buf,combobuf[combo->combos[cpos]].tile,x2,y2,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17669 }
17670 else
17671 {
17672 overtile16(buf,combobuf[combo->combos[cpos]].tile,x2,y2,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17673 }
17674 }
17675 }
17676 }
17677 }
17678
17679 stretch_blit(buf, buf2, 0, 0, (cw*16), (ch*16), sx*size, sy*size, sw*size, sh*size);
17680 blit(buf2, dest, 0, 0, x, y, 16*size, 16*size);
17681 }
17682 else
17683 {
17684 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17685 rectfill(dest,x+3*size,y+3*size,x+12*size,y+12*size,vc(4));
17686 }
17687
17688 if(buf)
17689 destroy_bitmap(buf);
17690
17691 if(buf2)
17692 destroy_bitmap(buf2);
17693 }
17694 else
17695 {
17696 if(combobuf[combo->combo].tile>0)
17697 {
17698 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17699 put_combo(dest, x, y, combo->combo, combo->cset, 0, 0, size);
17700 }
17701 else
17702 {
17703 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17704 rectfill(dest,x+3*size,y+3*size,x+12*size,y+12*size,vc(4));
17705 }
17706 }
17707 }
17708
17709 int32_t d_comboat_proc(int32_t msg,DIALOG *d,int32_t)
17710 {
17711 switch(msg)
17712 {
17713 case MSG_CLICK:
17714 {
17715 int32_t c2;
17716 int32_t cs;
17717 c2=temp_aliases[comboa_cnt].combo;
17718 cs=temp_aliases[comboa_cnt].cset;
17719
17720 if(gui_mouse_b()&2) //right mouse button
17721 {
17722 if(c2==0&&cs==0&&!(gui_mouse_b()&1))
17723 {
17724 return D_O_K;
17725 }
17726
17727 temp_aliases[comboa_cnt].combo=0;
17728 temp_aliases[comboa_cnt].cset=0;
17729 }
17730
17731 if(gui_mouse_b()&1) //left mouse button
17732 {
17733 if(select_combo_2(c2, cs))
17734 {
17735 temp_aliases[comboa_cnt].combo=c2;
17736 temp_aliases[comboa_cnt].cset=cs;
17737 }
17738
17739 return D_REDRAW;
17740 }
17741 else
17742 {
17743 return D_REDRAWME;
17744 }
17745 }
17746 break;
17747
17748 case MSG_DRAW:
17749 draw_combo_alias_thumbnail(screen, &temp_aliases[comboa_cnt], d->x-1, d->y-1,2);
17750 break;
17751
17752 default:
17753 break;
17754 }
17755
17756 return D_O_K;
17757 }
17758
17759 int32_t d_comboa_radio_proc(int32_t msg,DIALOG *d,int32_t c);
17760
17761 static DIALOG orgcomboa_dlg[] =
17762 {
17763 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
17764 { jwin_win_proc, 0, 0, 200, 161, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Organize Combo Aliases", NULL, NULL },
17765 { jwin_button_proc, 27, 130, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
17766 { jwin_button_proc, 112, 130, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
17767
17768 { jwin_radio_proc, 10, 40, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Copy", NULL, NULL },
17769 { jwin_text_proc, 10, 50, 33, 9, 0, 0, 0, 0, 0, 0, (void *) "", NULL, NULL },
17770 // { jwin_radio_proc, 10, 50, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Move", NULL, NULL },
17771 { jwin_radio_proc, 10, 60, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Swap", NULL, NULL },
17772 /* 6 */ { jwin_edit_proc, 110, 35, 32, 16, vc(12), vc(1), 0, 0, 4, 0, NULL, NULL, NULL },
17773 { jwin_edit_proc, 110, 55, 32, 16, vc(12), vc(1), 0, 0, 4, 0, NULL, NULL, NULL },
17774 { jwin_text_proc, 60, 40, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Source", NULL, NULL },
17775 { jwin_text_proc, 60, 60, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Dest", NULL, NULL},
17776 { jwin_radio_proc, 10, 80, 60, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Insert new (before source)", NULL, NULL },
17777 { jwin_radio_proc, 10, 100, 60, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Delete source", NULL, NULL },
17778 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17779 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17780 };
17781
17782 static DIALOG newcomboa_dlg[] =
17783 {
17784 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
17785 { jwin_win_proc, 0, 0, 200, 161, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Alias Properties", NULL, NULL },
17786 { jwin_button_proc, 27, 130, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
17787 { jwin_button_proc, 112, 130, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
17788 { jwin_text_proc, 24, 34, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Alias Width", NULL, NULL },
17789 { jwin_text_proc, 24, 52, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Alias Height", NULL, NULL },
17790 { jwin_text_proc, 24, 70, 100, 8, 0, 0, 0, 0, 0, 0, (void *) "Layers to Draw On:", NULL, NULL },
17791 { jwin_edit_proc, 104, 30, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17792 { jwin_edit_proc, 122, 48, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17793 { jwin_check_proc, 24, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "1", NULL, NULL },
17794 { jwin_check_proc, 50, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "2", NULL, NULL },
17795 { jwin_check_proc, 76, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "3", NULL, NULL },
17796 { jwin_check_proc, 102, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "4", NULL, NULL },
17797 { jwin_check_proc, 128, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "5", NULL, NULL },
17798 { jwin_check_proc, 154, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "6", NULL, NULL },
17799
17800
17801 // { jwin_text_proc, 24, 106, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Copy to :", NULL, NULL },
17802 //15
17803 // { jwin_edit_proc, 100, 100, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17804 // { jwin_check_proc, 84, 106, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "", NULL, NULL },
17805
17806 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17807 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17808 };
17809
17810 bool swapComboAlias(int32_t source, int32_t dest)
17811 {
17812 if(source==dest)
17813 return false;
17814 zc_swap(temp_aliases[source],temp_aliases[dest]);
17815 return true;
17816 }
17817
17818
17819 bool copyComboAlias(int32_t source, int32_t dest)
17820 {
17821 if(source == dest)
17822 return false;
17823 temp_aliases[dest] = temp_aliases[source];
17824 return true;
17825 }
17826
17827 int32_t getcurrentcomboalias();
17828
17829 int32_t onOrgComboAliases()
17830 {
17831 char cSrc[8];
17832 char cDest[8];
17833 sprintf(cSrc,"%d", getcurrentcomboalias());
17834 strcpy(cDest,cSrc);
17835 int32_t iSrc = 0;
17836 int32_t iDest = 0;
17837
17838 //sprintf(cSrc,"0");
17839 //sprintf(cDest,"0");
17840 orgcomboa_dlg[0].dp2=get_zc_font(font_lfont);
17841 orgcomboa_dlg[6].dp= cSrc;
17842 orgcomboa_dlg[7].dp= cDest;
17843 int32_t ret = 1;
17844 large_dialog(orgcomboa_dlg);
17845 do
17846 {
17847 iSrc = atoi((char*)orgcomboa_dlg[6].dp);
17848 iDest = atoi((char*)orgcomboa_dlg[7].dp);
17849 ret = do_zqdialog(orgcomboa_dlg,-1);
17850
17851 if(ret!=1) return ret;
17852
17853 if((atoi((char*) orgcomboa_dlg[6].dp))<0 || (atoi((char*) orgcomboa_dlg[6].dp)) > MAXCOMBOALIASES-1)
17854 {
17855 char buf[100];
17856 snprintf(buf, 100, "Invalid source (range 0-%d)", MAXCOMBOALIASES-1);
17857 buf[99]='\0';
17858 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
17859 ret = 1;
17860 }
17861
17862 // 10,11=ins, del
17863 if(orgcomboa_dlg[10].flags & D_SELECTED) //insert
17864 {
17865 for(int32_t j=MAXCOMBOALIASES-1; j>(atoi((char*) orgcomboa_dlg[6].dp)); --j)
17866 copyComboAlias(j-1,j);
17867 ret = -1;
17868 }
17869
17870 if(orgcomboa_dlg[11].flags & D_SELECTED) //delete
17871 {
17872 for(int32_t j=(atoi((char*) orgcomboa_dlg[6].dp)); j<MAXCOMBOALIASES-1; ++j)
17873 copyComboAlias(j+1,j);
17874 ret = -1;
17875 }
17876
17877 if((atoi((char*) orgcomboa_dlg[6].dp)) == (atoi((char*) orgcomboa_dlg[7].dp)))
17878 {
17879 jwin_alert("Error","Source and dest can't be the same.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
17880 ret = 1;
17881 }
17882
17883 if((atoi((char*) orgcomboa_dlg[7].dp)) < 0 || (atoi((char*) orgcomboa_dlg[7].dp)) > MAXCOMBOALIASES-1)
17884 {
17885 char buf[100];
17886 snprintf(buf, 100, "Invalid dest (range 0-%d)", MAXCOMBOALIASES-1);
17887 buf[99]='\0';
17888
17889 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
17890 ret = 1;
17891 }
17892
17893 if(orgcomboa_dlg[3].flags & D_SELECTED) //copy
17894 {
17895 copyComboAlias((atoi((char*) orgcomboa_dlg[6].dp)),(atoi((char*) orgcomboa_dlg[7].dp)));
17896 ret = -1;
17897 }
17898
17899 if(orgcomboa_dlg[5].flags & D_SELECTED) //swap
17900 {
17901 swapComboAlias((atoi((char*) orgcomboa_dlg[6].dp)),(atoi((char*) orgcomboa_dlg[7].dp)));
17902 ret = -1;
17903 }
17904 }
17905 while(ret==1);
17906 return ret;
17907 }
17908
17909 int32_t onNewComboAlias()
17910 {
17911 combo_alias *combo;
17912 combo = &temp_aliases[comboa_cnt];
17913
17914 char cwidth[5];
17915 char cheight[5];
17916 // char cp[3];
17917
17918 word temp_combos[16*11*7];
17919 byte temp_csets[16*11*7];
17920 sprintf(cwidth, "%d", combo->width+1);
17921 sprintf(cheight, "%d", combo->height+1);
17922 int32_t old_count = (comboa_lmasktotal(combo->layermask)+1)*(combo->width+1)*(combo->height+1);
17923 int32_t old_width=combo->width;
17924 int32_t old_height=combo->height;
17925 int32_t oldlayer=combo->layermask;
17926
17927 for(int32_t i=0; i<old_count; i++)
17928 {
17929 temp_csets[i] = combo->csets[i];
17930 temp_combos[i] = combo->combos[i];
17931 }
17932
17933 newcomboa_dlg[0].dp2 = get_zc_font(font_lfont);
17934 newcomboa_dlg[6].dp = cwidth;
17935 newcomboa_dlg[7].dp = cheight;
17936 newcomboa_dlg[8].flags = (combo->layermask&1)? D_SELECTED : 0;
17937 newcomboa_dlg[9].flags = (combo->layermask&2)? D_SELECTED : 0;
17938 newcomboa_dlg[10].flags = (combo->layermask&4)? D_SELECTED : 0;
17939 newcomboa_dlg[11].flags = (combo->layermask&8)? D_SELECTED : 0;
17940 newcomboa_dlg[12].flags = (combo->layermask&16)? D_SELECTED : 0;
17941 newcomboa_dlg[13].flags = (combo->layermask&32)? D_SELECTED : 0;
17942
17943 large_dialog(newcomboa_dlg);
17944
17945 int32_t ret = do_zqdialog(newcomboa_dlg,-1);
17946
17947 if(ret==1)
17948 {
17949 combo->width = ((atoi(cwidth)-1)<16)?zc_max(0,(atoi(cwidth)-1)):15;
17950 combo->height = ((atoi(cheight)-1)<11)?zc_max(0,(atoi(cheight)-1)):10;
17951 combo->layermask=0;
17952 combo->layermask |= (newcomboa_dlg[8].flags&D_SELECTED)?1:0;
17953 combo->layermask |= (newcomboa_dlg[9].flags&D_SELECTED)?2:0;
17954 combo->layermask |= (newcomboa_dlg[10].flags&D_SELECTED)?4:0;
17955 combo->layermask |= (newcomboa_dlg[11].flags&D_SELECTED)?8:0;
17956 combo->layermask |= (newcomboa_dlg[12].flags&D_SELECTED)?16:0;
17957 combo->layermask |= (newcomboa_dlg[13].flags&D_SELECTED)?32:0;
17958
17959 int32_t new_count = (comboa_lmasktotal(combo->layermask)+1)*(combo->width+1)*(combo->height+1);
17960
17961 combo->combos.clear();
17962 combo->csets.clear();
17963
17964 int32_t j=1;
17965 int32_t old_size=(old_width+1)*(old_height+1);
17966 int32_t new_start[7] =
17967 {
17968 0,
17969 ((combo->width+1)*(combo->height+1)*(1)),
17970 ((combo->width+1)*(combo->height+1)*(2)),
17971 ((combo->width+1)*(combo->height+1)*(3)),
17972 ((combo->width+1)*(combo->height+1)*(4)),
17973 ((combo->width+1)*(combo->height+1)*(5)),
17974 ((combo->width+1)*(combo->height+1)*(6))
17975 };
17976 int32_t new_layers[6] = {0,0,0,0,0,0};
17977 int32_t temp_layer = combo->layermask;
17978 int32_t temp_old = oldlayer;
17979 int32_t old_layers[6] = {0,0,0,0,0,0};
17980 int32_t k=1;
17981
17982 for(int32_t i=0; (i<6)&&(temp_layer!=0); j++,temp_layer>>=1,temp_old>>=1)
17983 {
17984 if(temp_layer&1)
17985 {
17986 new_layers[i] = j;
17987 //if(oldlayer&(1<<(j-1))) old_layers[i] = k++;
17988 i++;
17989 }
17990
17991 if(temp_old&1)
17992 {
17993 if(temp_layer&1)
17994 {
17995 old_layers[i-1] = k;
17996 }
17997
17998 k++;
17999 }
18000 }
18001
18002 for(int32_t i=0; i<new_count; i++)
18003 {
18004 if(i>=new_start[6])
18005 {
18006 //oldl=oldlayer>>(new_layers[5]-1);
18007 j=i-new_start[6];
18008
18009 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[5]-1))))
18010 {
18011 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[5])];
18012 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[5])];
18013 }
18014 else
18015 {
18016 combo->combos[i] = 0;
18017 combo->csets[i] = 0;
18018 }
18019 }
18020 else if(i>=new_start[5])
18021 {
18022 //oldl=oldlayer>>(new_layers[4]-1);
18023 j=i-new_start[5];
18024
18025 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[4]-1))))
18026 {
18027 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[4])];
18028 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[4])];
18029 }
18030 else
18031 {
18032 combo->combos[i] = 0;
18033 combo->csets[i] = 0;
18034 }
18035 }
18036 else if(i>=new_start[4])
18037 {
18038 //oldl=oldlayer>>(new_layers[3]-1);
18039 j=i-new_start[4];
18040
18041 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[3]-1))))
18042 {
18043 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[3])];
18044 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[3])];
18045 }
18046 else
18047 {
18048 combo->combos[i] = 0;
18049 combo->csets[i] = 0;
18050 }
18051 }
18052 else if(i>=new_start[3])
18053 {
18054 //oldl=oldlayer>>(new_layers[2]-1);
18055 j=i-new_start[3];
18056
18057 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[2]-1))))
18058 {
18059 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[2])];
18060 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[2])];
18061 }
18062 else
18063 {
18064 combo->combos[i] = 0;
18065 combo->csets[i] = 0;
18066 }
18067 }
18068 else if(i>=new_start[2])
18069 {
18070 //oldl=oldlayer>>(new_layers[1]-1);
18071 j=i-new_start[2];
18072
18073 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[1]-1))))
18074 {
18075 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[1])];
18076 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[1])];
18077 }
18078 else
18079 {
18080 combo->combos[i] = 0;
18081 combo->csets[i] = 0;
18082 }
18083 }
18084 else if(i>=new_start[1])
18085 {
18086 //oldl=oldlayer>>(new_layers[0]-1);
18087 j=i-new_start[1];
18088
18089 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[0]-1))))
18090 {
18091 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[0])];
18092 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[0])];
18093 }
18094 else
18095 {
18096 combo->combos[i] = 0;
18097 combo->csets[i] = 0;
18098 }
18099 }
18100 else if(i>=new_start[0])
18101 {
18102 if(((i/(combo->width+1))<=old_height)&&((i%(combo->width+1))<=old_width))
18103 {
18104 combo->combos[i] = temp_combos[(i%(combo->width+1))+((old_width+1)*(i/(combo->width+1)))];
18105 combo->csets[i] = temp_csets[(i%(combo->width+1))+((old_width+1)*(i/(combo->width+1)))];
18106 }
18107 else
18108 {
18109 combo->combos[i] = 0;
18110 combo->csets[i] = 0;
18111 }
18112 }
18113 }
18114
18115 set_comboaradio(combo->layermask);
18116 }
18117
18118 return ret;
18119 }
18120
18121 int32_t d_orgcomboa_proc(int32_t msg, DIALOG *d, int32_t c)
18122 {
18123 //these are here to bypass compiler warnings about unused arguments
18124 c=c;
18125
18126 int32_t down=0;
18127 int32_t selected=(d->flags&D_SELECTED)?1:0;
18128 int32_t last_draw;
18129
18130 switch(msg)
18131 {
18132
18133 case MSG_DRAW:
18134 {
18135 FONT *tfont=font;
18136 font=get_zc_font(font_lfont_l);
18137 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, true);
18138 font=tfont;
18139 }
18140 break;
18141
18142 case MSG_WANTFOCUS:
18143 return D_WANTFOCUS;
18144
18145 case MSG_KEY:
18146 /* close dialog? */
18147 onOrgComboAliases();
18148 return D_REDRAW;
18149
18150 /* or just toggle */
18151 /*d->flags ^= D_SELECTED;
18152 object_message(d, MSG_DRAW, 0);
18153 break;*/
18154
18155 case MSG_CLICK:
18156 last_draw = 0;
18157
18158 /* track the mouse until it is released */
18159 while(gui_mouse_b())
18160 {
18161 down = mouse_in_rect(d->x, d->y, d->w, d->h);
18162
18163 /* redraw? */
18164 if(last_draw != down)
18165 {
18166 if(down != selected)
18167 d->flags |= D_SELECTED;
18168 else
18169 d->flags &= ~D_SELECTED;
18170
18171 object_message(d, MSG_DRAW, 0);
18172 last_draw = down;
18173 }
18174
18175 /* let other objects continue to animate */
18176 broadcast_dialog_message(MSG_IDLE, 0);
18177 }
18178
18179 /* redraw in normal state */
18180 if(down)
18181 {
18182 if(d->flags&D_EXIT)
18183 {
18184 d->flags &= ~D_SELECTED;
18185 object_message(d, MSG_DRAW, 0);
18186 }
18187 }
18188
18189 /* should we close the dialog? */
18190 if(down)
18191 {
18192 onOrgComboAliases();
18193 return D_REDRAW;
18194 }
18195
18196 break;
18197 }
18198
18199 return D_O_K;
18200 }
18201
18202 int32_t d_comboabutton_proc(int32_t msg, DIALOG *d, int32_t c)
18203 {
18204 //these are here to bypass compiler warnings about unused arguments
18205 c=c;
18206
18207 int32_t down=0;
18208 int32_t selected=(d->flags&D_SELECTED)?1:0;
18209 int32_t last_draw;
18210
18211 switch(msg)
18212 {
18213
18214 case MSG_DRAW:
18215 {
18216 FONT *tfont=font;
18217 font=get_zc_font(font_lfont_l);
18218 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, true);
18219 font=tfont;
18220 }
18221 break;
18222
18223 case MSG_WANTFOCUS:
18224 return D_WANTFOCUS;
18225
18226 case MSG_KEY:
18227 /* close dialog? */
18228 onNewComboAlias();
18229 return D_REDRAW;
18230
18231 /* or just toggle */
18232 /*d->flags ^= D_SELECTED;
18233 object_message(d, MSG_DRAW, 0);
18234 break;*/
18235
18236 case MSG_CLICK:
18237 last_draw = 0;
18238
18239 /* track the mouse until it is released */
18240 while(gui_mouse_b())
18241 {
18242 down = mouse_in_rect(d->x, d->y, d->w, d->h);
18243
18244 /* redraw? */
18245 if(last_draw != down)
18246 {
18247 if(down != selected)
18248 d->flags |= D_SELECTED;
18249 else
18250 d->flags &= ~D_SELECTED;
18251
18252 object_message(d, MSG_DRAW, 0);
18253 last_draw = down;
18254 }
18255
18256 /* let other objects continue to animate */
18257 broadcast_dialog_message(MSG_IDLE, 0);
18258 }
18259
18260 /* redraw in normal state */
18261 if(down)
18262 {
18263 if(d->flags&D_EXIT)
18264 {
18265 d->flags &= ~D_SELECTED;
18266 object_message(d, MSG_DRAW, 0);
18267 }
18268 }
18269
18270 /* should we close the dialog? */
18271 if(down)
18272 {
18273 onNewComboAlias();
18274 return D_REDRAW;
18275 }
18276
18277 break;
18278 }
18279
18280 return D_O_K;
18281 }
18282
18283 int32_t d_comboacheck_proc(int32_t msg, DIALOG *d, int32_t c)
18284 {
18285 int32_t temp = d->flags&D_SELECTED;
18286 int32_t ret=jwin_checkfont_proc(msg,d,c);
18287
18288 if(temp != (d->flags&D_SELECTED))
18289 {
18290 return D_REDRAW;
18291 }
18292
18293 return ret;
18294 }
18295
18296 12 static ListData comboa_list(comboalist, &font);
18297
18298 static DIALOG editcomboa_dlg[] =
18299 {
18300 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
18301 { jwin_win_proc, 0, 0, 320, 240, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Alias Edit", NULL, NULL },
18302 { jwin_button_proc, 148, 212, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
18303 { jwin_button_proc, 232, 212, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
18304 { jwin_frame_proc, 4+121, 28+81, 1, 1, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18305 { d_comboabutton_proc, 25, 212, 81, 21, vc(14), vc(1), 'p', D_EXIT, 0, 0, (void *) "&Properties", NULL, NULL },
18306 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18307 { d_comboa_radio_proc, 285, 44, 30, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "0", NULL, NULL },
18308 { d_comboa_radio_proc, 285, 54, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
18309 { d_comboa_radio_proc, 285, 64, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "2", NULL, NULL },
18310 { d_comboa_radio_proc, 285, 74, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "3", NULL, NULL },
18311 { d_comboa_radio_proc, 285, 84, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "4", NULL, NULL },
18312
18313 { d_comboa_radio_proc, 285, 94, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "5", NULL, NULL },
18314 { d_comboa_radio_proc, 285, 104, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "6", NULL, NULL },
18315 { d_comboacheck_proc, 285, 164, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
18316 { d_comboa_proc, 6, 27, 256, 176, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18317 { jwin_ctext_proc, 290, 176, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Only Show", NULL, NULL },
18318 { jwin_ctext_proc, 290, 186, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Current", NULL, NULL },
18319 { jwin_ctext_proc, 290, 196, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Layer", NULL, NULL },
18320 { jwin_ctext_proc, 290, 122, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Thumbnail", NULL, NULL },
18321 { jwin_frame_proc, 280, 132, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18322 { d_comboat_proc, 282, 134, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18323
18324 //21
18325 { d_orgcomboa_proc, 106, 212, 21, 21, vc(14), vc(1), 'p', D_EXIT, 0, 0, (void *) "&Org", NULL, NULL },
18326 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18327 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18328 };
18329
18330 int32_t getcurrentcomboalias()
18331 {
18332 return editcomboa_dlg[5].d1;
18333 }
18334
18335 int32_t d_comboa_radio_proc(int32_t msg,DIALOG *d,int32_t c)
18336 {
18337 int32_t temp = layer_cnt;
18338 int32_t ret = jwin_radiofont_proc(msg,d,c);
18339
18340 if(editcomboa_dlg[6].flags&D_SELECTED) layer_cnt=0;
18341 else if(editcomboa_dlg[7].flags&D_SELECTED) layer_cnt=1;
18342 else if(editcomboa_dlg[8].flags&D_SELECTED) layer_cnt=2;
18343 else if(editcomboa_dlg[9].flags&D_SELECTED) layer_cnt=3;
18344 else if(editcomboa_dlg[10].flags&D_SELECTED) layer_cnt=4;
18345 else if(editcomboa_dlg[11].flags&D_SELECTED) layer_cnt=5;
18346 else if(editcomboa_dlg[12].flags&D_SELECTED) layer_cnt=6;
18347
18348 if(temp != layer_cnt)
18349 {
18350 return D_REDRAW;
18351 }
18352
18353 return ret;
18354 }
18355
18356 int32_t set_comboaradio(byte layermask)
18357 {
18358 if(editcomboa_dlg[7].flags&D_SELECTED) editcomboa_dlg[7].flags &= ~D_SELECTED;
18359
18360 if(editcomboa_dlg[8].flags&D_SELECTED) editcomboa_dlg[8].flags &= ~D_SELECTED;
18361
18362 if(editcomboa_dlg[9].flags&D_SELECTED) editcomboa_dlg[9].flags &= ~D_SELECTED;
18363
18364 if(editcomboa_dlg[10].flags&D_SELECTED) editcomboa_dlg[10].flags &= ~D_SELECTED;
18365
18366 if(editcomboa_dlg[11].flags&D_SELECTED) editcomboa_dlg[11].flags &= ~D_SELECTED;
18367
18368 if(editcomboa_dlg[12].flags&D_SELECTED) editcomboa_dlg[12].flags &= ~D_SELECTED;
18369
18370 if(!(layermask&1)) editcomboa_dlg[7].flags |= D_DISABLED;
18371 else editcomboa_dlg[7].flags &= ~D_DISABLED;
18372
18373 if(!(layermask&2)) editcomboa_dlg[8].flags |= D_DISABLED;
18374 else editcomboa_dlg[8].flags &= ~D_DISABLED;
18375
18376 if(!(layermask&4)) editcomboa_dlg[9].flags |= D_DISABLED;
18377 else editcomboa_dlg[9].flags &= ~D_DISABLED;
18378
18379 if(!(layermask&8)) editcomboa_dlg[10].flags |= D_DISABLED;
18380 else editcomboa_dlg[10].flags &= ~D_DISABLED;
18381
18382 if(!(layermask&16)) editcomboa_dlg[11].flags |= D_DISABLED;
18383 else editcomboa_dlg[11].flags &= ~D_DISABLED;
18384
18385 if(!(layermask&32)) editcomboa_dlg[12].flags |= D_DISABLED;
18386 else editcomboa_dlg[12].flags &= ~D_DISABLED;
18387
18388 editcomboa_dlg[6].flags |= D_SELECTED;
18389 layer_cnt=0;
18390 return 1;
18391 }
18392
18393 int32_t onEditComboPool()
18394 {
18395 call_cpool_dlg(combo_pool_pos);
18396 return D_O_K;
18397 }
18398 int32_t onEditAutoCombo()
18399 {
18400 call_autocombo_dlg(combo_auto_pos);
18401 return D_O_K;
18402 }
18403 int32_t onEditComboAlias()
18404 {
18405 comboa_cnt = combo_apos;
18406 reset_combo_animations();
18407 reset_combo_animations2();
18408
18409 for(int32_t i=0; i<MAXCOMBOALIASES; i++)
18410 temp_aliases[i] = combo_aliases[i];
18411
18412 editcomboa_dlg[0].dp2 = get_zc_font(font_lfont);
18413 set_comboaradio(temp_aliases[comboa_cnt].layermask);
18414 editcomboa_dlg[5].d1 = comboa_cnt;
18415
18416 bool small_d1 = editcomboa_dlg[0].d1==0;
18417 large_dialog(editcomboa_dlg,2);
18418
18419 if(small_d1)
18420 {
18421 for(int32_t i=6; i<=12; i++)
18422 {
18423 editcomboa_dlg[i].w=30*1.5;
18424 editcomboa_dlg[i].h=9*1.5;
18425 }
18426
18427 editcomboa_dlg[13].w=17*1.5;
18428 editcomboa_dlg[13].h=9*1.5;
18429 editcomboa_dlg[4].w=81*1.5;
18430 editcomboa_dlg[4].h=21*1.5;
18431 editcomboa_dlg[4].dp2=get_zc_font(font_lfont_l);
18432 editcomboa_dlg[21].w=21*1.5;
18433 editcomboa_dlg[21].h=21*1.5;
18434 editcomboa_dlg[21].dp2=get_zc_font(font_lfont_l);
18435 }
18436
18437 int32_t ret=do_zqdialog(editcomboa_dlg,-1);
18438
18439 if(ret==1)
18440 {
18441 saved=false;
18442
18443 for(int32_t i=0; i<MAXCOMBOALIASES; i++)
18444 combo_aliases[i] = temp_aliases[i];
18445 }
18446
18447 setup_combo_animations();
18448 setup_combo_animations2();
18449 return D_O_K;
18450 }
18451 void call_calias_dlg(int index)
18452 {
18453 combo_apos = comboa_cnt = index;
18454 onEditComboAlias();
18455 }
18456
18457 static char ffcombo_str_buf[MAXFFCS];
18458 static char fflink_str_buf[MAXFFCS];
18459
18460 BITMAP* ffcur;
18461
18462 const char *ffcombolist(int32_t index, int32_t *list_size)
18463 {
18464 if(index>=0)
18465 {
18466 bound(index,0,MAXFFCS-1);
18467 sprintf(ffcombo_str_buf,"%d",index+1);
18468 return ffcombo_str_buf;
18469 }
18470
18471 *list_size=MAXFFCS;
18472 return NULL;
18473 }
18474
18475 12 static ListData ffcombo_list(ffcombolist, &font);
18476
18477 static DIALOG ffcombo_sel_dlg[] =
18478 {
18479 12 { jwin_win_proc, 0, 0, 200, 179, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Choose Freeform Combo", NULL, NULL },
18480 12 { jwin_button_proc, 35, 152, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
18481 12 { jwin_button_proc, 104, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
18482 12 { d_ffcombolist_proc, 11, 24, 49, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 1, 0, (void *) &ffcombo_list, NULL, NULL },
18483 12 { d_comboframe_proc, 68, 23, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18484 12 { d_bitmap_proc, 70, 25, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18485 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18486 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18487 };
18488
18489 int32_t d_ffcombolist_proc(int32_t msg,DIALOG *d,int32_t c)
18490 {
18491 int32_t ret = jwin_droplist_proc(msg,d,c);
18492 int32_t d1 = d->d1;
18493 int32_t x=ffcombo_sel_dlg[0].x;
18494 int32_t y=ffcombo_sel_dlg[0].y;
18495 FONT *tempfont=(font);
18496 int32_t x2=text_length(tempfont, "Move Delay:")+4;
18497
18498 switch(msg)
18499 {
18500 case MSG_DRAW:
18501 if(!ffcur) return D_O_K;
18502
18503 BITMAP *buf = create_bitmap_ex(8,16,16);
18504
18505 if(buf)
18506 {
18507 clear_bitmap(buf);
18508 putcombo(buf,0,0,Map.CurrScr()->ffcs[d1].data,Map.CurrScr()->ffcs[d1].cset);
18509 stretch_blit(buf, ffcur, 0,0, 16, 16, 0, 0, ffcur->w, ffcur->h);
18510 destroy_bitmap(buf);
18511 }
18512
18513 object_message(&ffcombo_sel_dlg[5],MSG_DRAW,0);
18514
18515 int32_t xd = x+int32_t(68*1.5);
18516 int32_t y2 = y+int32_t(55*1.5);
18517 int32_t yd = 9;
18518
18519 rectfill(screen,xd,y2,xd+x2+100,y2+yd*14,jwin_pal[jcBOX]);
18520
18521 textprintf_ex(screen,tempfont,xd,y2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo #:");
18522 textprintf_ex(screen,tempfont,xd+x2,y2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].data);
18523
18524 textprintf_ex(screen,tempfont,xd,y2+yd,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"CSet #:");
18525 textprintf_ex(screen,tempfont,xd+x2,y2+yd,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].cset);
18526
18527 textprintf_ex(screen,tempfont,xd,y2+yd*2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Pos:");
18528 textprintf_ex(screen,tempfont,xd+x2,y2+yd*2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].x.getFloat());
18529
18530 textprintf_ex(screen,tempfont,xd,y2+yd*3,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Pos:");
18531 textprintf_ex(screen,tempfont,xd+x2,y2+yd*3,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].y.getFloat());
18532
18533 textprintf_ex(screen,tempfont,xd,y2+yd*4,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Speed:");
18534 textprintf_ex(screen,tempfont,xd+x2,y2+yd*4,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].vx.getFloat());
18535
18536 textprintf_ex(screen,tempfont,xd,y2+yd*5,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Speed:");
18537 textprintf_ex(screen,tempfont,xd+x2,y2+yd*5,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].vy.getFloat());
18538
18539 textprintf_ex(screen,tempfont,xd,y2+yd*6,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Accel:");
18540 textprintf_ex(screen,tempfont,xd+x2,y2+yd*6,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].ax.getFloat());
18541
18542 textprintf_ex(screen,tempfont,xd,y2+yd*7,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Accel:");
18543 textprintf_ex(screen,tempfont,xd+x2,y2+yd*7,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].ay.getFloat());
18544
18545 textprintf_ex(screen,tempfont,xd,y2+yd*8,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Linked To:");
18546 textprintf_ex(screen,tempfont,xd+x2,y2+yd*8,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].link);
18547
18548 textprintf_ex(screen,tempfont,xd,y2+yd*9,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Move Delay:");
18549 textprintf_ex(screen,tempfont,xd+x2,y2+yd*9,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].delay);
18550
18551 textprintf_ex(screen,tempfont,xd,y2+yd*10,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo W:");
18552 textprintf_ex(screen,tempfont,xd+x2,y2+yd*10,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffEffectWidth(d1)));
18553
18554 textprintf_ex(screen,tempfont,xd,y2+yd*11,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo H:");
18555 textprintf_ex(screen,tempfont,xd+x2,y2+yd*11,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffEffectHeight(d1)));
18556
18557 textprintf_ex(screen,tempfont,xd,y2+yd*12,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Tile W:");
18558 textprintf_ex(screen,tempfont,xd+x2,y2+yd*12,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffTileWidth(d1)));
18559
18560 textprintf_ex(screen,tempfont,xd,y2+yd*13,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Tile H:");
18561 textprintf_ex(screen,tempfont,xd+x2,y2+yd*13,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffTileHeight(d1)));
18562
18563 break;
18564 }
18565
18566 return ret;
18567 }
18568 int32_t onSelectFFCombo()
18569 {
18570 ffcombo_sel_dlg[0].dp2 = get_zc_font(font_lfont);
18571 ffcombo_sel_dlg[3].d1 = ff_combo;
18572 ffcur = create_bitmap_ex(8,32,32);
18573
18574 if(!ffcur) return D_O_K;
18575
18576 Map.CurrScr()->ensureFFC(MAXFFCS - 1);
18577 putcombo(ffcur,0,0,Map.CurrScr()->ffcs[ff_combo].data,Map.CurrScr()->ffcs[ff_combo].cset);
18578 ffcombo_sel_dlg[5].dp = ffcur;
18579
18580 bool resize = !(ffcombo_sel_dlg[0].d1);
18581 large_dialog(ffcombo_sel_dlg);
18582
18583 if(resize)
18584 {
18585 ffcombo_sel_dlg[5].x--;
18586 ffcombo_sel_dlg[5].y--;
18587 }
18588
18589 int32_t ret=do_zqdialog(ffcombo_sel_dlg,0);
18590
18591 while(ret==1)
18592 {
18593 ff_combo = ffcombo_sel_dlg[3].d1;
18594 mapscr* scr = active_visible_screen ? active_visible_screen->scr : Map.CurrScr();
18595 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
18596 call_ffc_dialog(ff_combo, scr, screen);
18597 ret=do_zqdialog(ffcombo_sel_dlg,0);
18598 }
18599
18600 destroy_bitmap(ffcur);
18601 return D_O_K;
18602 }
18603
18604 const char *globalscriptlist(int32_t index, int32_t *list_size);
18605 12 static ListData globalscript_list(globalscriptlist, &font);
18606 const char *playerscriptlist(int32_t index, int32_t *list_size);
18607 12 static ListData playerscript_list(playerscriptlist, &font);
18608
18609 const char *ffscriptlist(int32_t index, int32_t *list_size);
18610
18611 12 static ListData ffscript_list(ffscriptlist, &font);
18612
18613 char *strip_decimals(char *string)
18614 {
18615 int32_t len=(int32_t)strlen(string);
18616 char *src=(char *)malloc(len+1);
18617 char *tmpsrc=src;
18618 memcpy(src,string,len+1);
18619 memset(src,0,len+1);
18620
18621 for(size_t i=0; string[i]&&i<=strlen(string); i++)
18622 {
18623 *tmpsrc=string[i];
18624
18625 if(*tmpsrc=='.')
18626 {
18627 while(string[i+1]=='.'&&i<=strlen(string))
18628 {
18629 i++;
18630 }
18631 }
18632
18633 tmpsrc++;
18634 }
18635
18636 memcpy(string,src,len);
18637 free(src);
18638 return string;
18639 }
18640
18641 // Unused??? -L 6/6/11
18642 char *clean_numeric_string(char *string)
18643 {
18644 bool found_sign=false;
18645 bool found_decimal=false;
18646 int32_t len=(int32_t)strlen(string);
18647 char *src=(char *)malloc(len+1);
18648 char *tmpsrc=src;
18649 memcpy(src,string,len+1);
18650 memset(src,0,len+1);
18651
18652 // strip out non-numerical characters
18653 for(size_t i=0; string[i]&&i<=strlen(string); i++)
18654 {
18655 *tmpsrc=string[i];
18656
18657 if(*tmpsrc!='.'&&*tmpsrc!='-'&&*tmpsrc!='+'&&!isdigit(*tmpsrc))
18658 {
18659 while(*tmpsrc!='.'&&*tmpsrc!='-'&&*tmpsrc!='+'&&!isdigit(*tmpsrc))
18660 {
18661 i++;
18662 }
18663 }
18664
18665 tmpsrc++;
18666 }
18667
18668 len=(int32_t)strlen(src);
18669 char *src2=(char *)malloc(len+1);
18670 tmpsrc=src2;
18671 memcpy(src,src2,len+1);
18672 memset(src2,0,len+1);
18673
18674 // second purge
18675 for(size_t i=0; src[i]&&i<=strlen(src); i++)
18676 {
18677 *tmpsrc=src[i];
18678
18679 if(*tmpsrc=='-'||*tmpsrc=='+')
18680 {
18681 if(found_sign||found_decimal)
18682 {
18683 while(*tmpsrc=='-'||*tmpsrc=='+')
18684 {
18685 i++;
18686 }
18687 }
18688
18689 found_sign=true;
18690 }
18691
18692 if(*tmpsrc=='.')
18693 {
18694 if(found_decimal)
18695 {
18696 while(*tmpsrc=='.')
18697 {
18698 i++;
18699 }
18700 }
18701
18702 found_decimal=true;
18703 }
18704
18705 tmpsrc++;
18706 }
18707
18708 sprintf(string, "%s", src2);
18709 free(src);
18710 free(src2);
18711 return string;
18712 }
18713
18714 script_struct biglobal[NUMSCRIPTGLOBAL+1]; //global script
18715 int32_t biglobal_cnt = -1;
18716 script_struct biffs[NUMSCRIPTFFC]; //ff script
18717 int32_t biffs_cnt = -1;
18718 script_struct biitems[NUMSCRIPTITEM]; //item script
18719 int32_t biitems_cnt = -1;
18720 script_struct binpcs[NUMSCRIPTGUYS]; //npc script
18721 int32_t binpcs_cnt = -1;
18722
18723 script_struct bilweapons[NUMSCRIPTWEAPONS]; //lweapon script
18724 int32_t bilweapons_cnt = -1;
18725
18726 script_struct bieweapons[NUMSCRIPTWEAPONS]; //eweapon script
18727 int32_t bieweapons_cnt = -1;
18728
18729 script_struct bihero[NUMSCRIPTHERO]; //link script
18730 int32_t bihero_cnt = -1;
18731
18732 script_struct biscreens[NUMSCRIPTSCREEN]; //screen (screendata) script
18733 int32_t biscreens_cnt = -1;
18734
18735 script_struct bidmaps[NUMSCRIPTSDMAP]; //dmap (dmapdata) script
18736 int32_t bidmaps_cnt = -1;
18737
18738 script_struct biditemsprites[NUMSCRIPTSITEMSPRITE]; //dmap (dmapdata) script
18739 int32_t biitemsprites_cnt = -1;
18740
18741 script_struct bidcomboscripts[NUMSCRIPTSCOMBODATA]; //dmap (dmapdata) script
18742 int32_t bidcomboscripts_cnt = -1;
18743 //static char ffscript_str_buf[32];
18744
18745 void build_biglobal_list()
18746 {
18747 biglobal[0].first = "(None)";
18748 biglobal[0].second = -1;
18749 biglobal_cnt = 1;
18750
18751 for(int32_t i = 0; i < NUMSCRIPTGLOBAL; ++i)
18752 {
18753 if(globalmap[i].scriptname.length()==0)
18754 continue;
18755
18756 stringstream ss;
18757 ss << globalmap[i].scriptname << " (" << i << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18758 biglobal[biglobal_cnt].first = ss.str();
18759 biglobal[biglobal_cnt].second = i;
18760 ++biglobal_cnt;
18761 }
18762
18763 // Blank out the rest of the list
18764 for(int32_t i=biglobal_cnt; i<NUMSCRIPTGLOBAL; ++i)
18765 {
18766 biglobal[i].first="";
18767 biglobal[i].second=-1;
18768 }
18769
18770 //Bubble sort! (doesn't account for gaps between scripts)
18771 for(int32_t i = 0; i < biglobal_cnt - 1; i++)
18772 {
18773 for(int32_t j = i + 1; j < biglobal_cnt; j++)
18774 {
18775 if(stricmp(biglobal[i].first.c_str(),biglobal[j].first.c_str()) > 0 && strcmp(biglobal[j].first.c_str(),""))
18776 zc_swap(biglobal[i],biglobal[j]);
18777 }
18778 }
18779
18780 biglobal_cnt = 0;
18781
18782 for(int32_t i = 0; i < NUMSCRIPTGLOBAL+1; ++i)
18783 if(biglobal[i].first.length() > 0)
18784 biglobal_cnt = i+1;
18785 }
18786
18787 6 void build_biffs_list()
18788 {
18789 6 biffs[0].first = "(None)";
18790 6 biffs[0].second = -1;
18791 6 biffs_cnt = 1;
18792
18793
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTFFC - 1; i++)
18794 {
18795
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 2987 times.
3066 if(ffcmap[i].scriptname.length()==0)
18796 2987 continue;
18797
18798 79 stringstream ss;
18799
5/10
✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 79 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 79 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 79 times.
✗ Branch 9 not taken.
79 ss << ffcmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18800
1/2
✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
79 biffs[biffs_cnt].first = ss.str();
18801 79 biffs[biffs_cnt].second = i;
18802 79 biffs_cnt++;
18803 79 }
18804
18805 // Blank out the rest of the list
18806
2/2
✓ Branch 0 taken 2987 times.
✓ Branch 1 taken 6 times.
2993 for(int32_t i=biffs_cnt; i<NUMSCRIPTFFC; i++)
18807 {
18808 2987 biffs[i].first="";
18809 2987 biffs[i].second=-1;
18810 2987 }
18811
18812 //Bubble sort! (doesn't account for gaps between scripts)
18813
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 6 times.
85 for(int32_t i = 0; i < biffs_cnt - 1; i++)
18814 {
18815
2/2
✓ Branch 0 taken 1383 times.
✓ Branch 1 taken 79 times.
1462 for(int32_t j = i + 1; j < biffs_cnt; j++)
18816 {
18817
3/4
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 843 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 540 times.
1383 if(stricmp(biffs[i].first.c_str(),biffs[j].first.c_str()) > 0 && strcmp(biffs[j].first.c_str(),""))
18818 540 zc_swap(biffs[i],biffs[j]);
18819 1383 }
18820 79 }
18821
18822 6 biffs_cnt = 0;
18823
18824
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i = 0; i < NUMSCRIPTFFC; i++)
18825
2/2
✓ Branch 0 taken 2987 times.
✓ Branch 1 taken 85 times.
3157 if(biffs[i].first.length() > 0)
18826 85 biffs_cnt = i+1;
18827 6 }
18828
18829 //npc scripts
18830 void build_binpcs_list()
18831 {
18832 binpcs[0].first = "(None)";
18833 binpcs[0].second = -1;
18834 binpcs_cnt = 1;
18835
18836 for(int32_t i = 0; i < NUMSCRIPTGUYS - 1; i++)
18837 {
18838 if(npcmap[i].scriptname.length()==0)
18839 continue;
18840
18841 stringstream ss;
18842 ss << npcmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18843 binpcs[binpcs_cnt].first = ss.str();
18844 binpcs[binpcs_cnt].second = i;
18845 binpcs_cnt++;
18846 }
18847
18848 // Blank out the rest of the list
18849 for(int32_t i=binpcs_cnt; i<NUMSCRIPTGUYS; i++)
18850 {
18851 binpcs[i].first="";
18852 binpcs[i].second=-1;
18853 }
18854
18855 //Bubble sort! (doesn't account for gaps between scripts)
18856 for(int32_t i = 0; i < binpcs_cnt - 1; i++)
18857 {
18858 for(int32_t j = i + 1; j < binpcs_cnt; j++)
18859 {
18860 if(stricmp(binpcs[i].first.c_str(),binpcs[j].first.c_str()) > 0 && strcmp(binpcs[j].first.c_str(),""))
18861 zc_swap(binpcs[i],binpcs[j]);
18862 }
18863 }
18864
18865 binpcs_cnt = 0;
18866
18867 for(int32_t i = 0; i < NUMSCRIPTGUYS; i++)
18868 if(binpcs[i].first.length() > 0)
18869 binpcs_cnt = i+1;
18870 }
18871
18872
18873 //lweapon scripts
18874 void build_bilweapons_list()
18875 {
18876 bilweapons[0].first = "(None)";
18877 bilweapons[0].second = -1;
18878 bilweapons_cnt = 1;
18879
18880 for(int32_t i = 0; i < NUMSCRIPTWEAPONS - 1; i++)
18881 {
18882 if(lwpnmap[i].scriptname.length()==0)
18883 continue;
18884
18885 stringstream ss;
18886 ss << lwpnmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18887 bilweapons[bilweapons_cnt].first = ss.str();
18888 bilweapons[bilweapons_cnt].second = i;
18889 bilweapons_cnt++;
18890 }
18891
18892 // Blank out the rest of the list
18893 for(int32_t i=bilweapons_cnt; i<NUMSCRIPTWEAPONS; i++)
18894 {
18895 bilweapons[i].first="";
18896 bilweapons[i].second=-1;
18897 }
18898
18899 //Bubble sort! (doesn't account for gaps between scripts)
18900 for(int32_t i = 0; i < bilweapons_cnt - 1; i++)
18901 {
18902 for(int32_t j = i + 1; j < bilweapons_cnt; j++)
18903 {
18904 if(stricmp(bilweapons[i].first.c_str(),bilweapons[j].first.c_str()) > 0 && strcmp(bilweapons[j].first.c_str(),""))
18905 zc_swap(bilweapons[i],bilweapons[j]);
18906 }
18907 }
18908
18909 bilweapons_cnt = 0;
18910
18911 for(int32_t i = 0; i < NUMSCRIPTWEAPONS; i++)
18912 if(bilweapons[i].first.length() > 0)
18913 bilweapons_cnt = i+1;
18914 }
18915
18916 //eweapon scripts
18917 void build_bieweapons_list()
18918 {
18919 bieweapons[0].first = "(None)";
18920 bieweapons[0].second = -1;
18921 bieweapons_cnt = 1;
18922
18923 for(int32_t i = 0; i < NUMSCRIPTWEAPONS - 1; i++)
18924 {
18925 if(ewpnmap[i].scriptname.length()==0)
18926 continue;
18927
18928 stringstream ss;
18929 ss << ewpnmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18930 bieweapons[bieweapons_cnt].first = ss.str();
18931 bieweapons[bieweapons_cnt].second = i;
18932 bieweapons_cnt++;
18933 }
18934
18935 // Blank out the rest of the list
18936 for(int32_t i=bieweapons_cnt; i<NUMSCRIPTWEAPONS; i++)
18937 {
18938 bieweapons[i].first="";
18939 bieweapons[i].second=-1;
18940 }
18941
18942 //Bubble sort! (doesn't account for gaps between scripts)
18943 for(int32_t i = 0; i < bieweapons_cnt - 1; i++)
18944 {
18945 for(int32_t j = i + 1; j < bieweapons_cnt; j++)
18946 {
18947 if(stricmp(bieweapons[i].first.c_str(),bieweapons[j].first.c_str()) > 0 && strcmp(bieweapons[j].first.c_str(),""))
18948 zc_swap(bieweapons[i],bieweapons[j]);
18949 }
18950 }
18951
18952 bieweapons_cnt = 0;
18953
18954 for(int32_t i = 0; i < NUMSCRIPTWEAPONS; i++)
18955 if(bieweapons[i].first.length() > 0)
18956 bieweapons_cnt = i+1;
18957 }
18958
18959 //player scripts
18960 void build_bihero_list()
18961 {
18962 bihero[0].first = "(None)";
18963 bihero[0].second = -1;
18964 bihero_cnt = 1;
18965
18966 for(int32_t i = 0; i < NUMSCRIPTHERO - 1; i++)
18967 {
18968 if(playermap[i].scriptname.length()==0)
18969 continue;
18970
18971 stringstream ss;
18972 ss << playermap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18973 bihero[bihero_cnt].first = ss.str();
18974 bihero[bihero_cnt].second = i;
18975 bihero_cnt++;
18976 }
18977
18978 // Blank out the rest of the list
18979 for(int32_t i=bihero_cnt; i<NUMSCRIPTHERO; i++)
18980 {
18981 bihero[i].first="";
18982 bihero[i].second=-1;
18983 }
18984
18985 //Bubble sort! (doesn't account for gaps between scripts)
18986 for(int32_t i = 0; i < bihero_cnt - 1; i++)
18987 {
18988 for(int32_t j = i + 1; j < bihero_cnt; j++)
18989 {
18990 if(stricmp(bihero[i].first.c_str(),bihero[j].first.c_str()) > 0 && strcmp(bihero[j].first.c_str(),""))
18991 zc_swap(bihero[i],bihero[j]);
18992 }
18993 }
18994
18995 bihero_cnt = 0;
18996
18997 for(int32_t i = 0; i < NUMSCRIPTHERO; i++)
18998 if(bihero[i].first.length() > 0)
18999 bihero_cnt = i+1;
19000 }
19001
19002 //dmap scripts
19003 void build_bidmaps_list()
19004 {
19005 bidmaps[0].first = "(None)";
19006 bidmaps[0].second = -1;
19007 bidmaps_cnt = 1;
19008
19009 for(int32_t i = 0; i < NUMSCRIPTSDMAP - 1; i++)
19010 {
19011 if(dmapmap[i].scriptname.length()==0)
19012 continue;
19013
19014 stringstream ss;
19015 ss << dmapmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19016 bidmaps[bidmaps_cnt].first = ss.str();
19017 bidmaps[bidmaps_cnt].second = i;
19018 bidmaps_cnt++;
19019 }
19020
19021 // Blank out the rest of the list
19022 for(int32_t i=bidmaps_cnt; i<NUMSCRIPTSDMAP; i++)
19023 {
19024 bidmaps[i].first="";
19025 bidmaps[i].second=-1;
19026 }
19027
19028 //Bubble sort! (doesn't account for gaps between scripts)
19029 for(int32_t i = 0; i < bidmaps_cnt - 1; i++)
19030 {
19031 for(int32_t j = i + 1; j < bidmaps_cnt; j++)
19032 {
19033 if(stricmp(bidmaps[i].first.c_str(),bidmaps[j].first.c_str()) > 0 && strcmp(bidmaps[j].first.c_str(),""))
19034 zc_swap(bidmaps[i],bidmaps[j]);
19035 }
19036 }
19037
19038 bidmaps_cnt = 0;
19039
19040 for(int32_t i = 0; i < NUMSCRIPTSDMAP; i++)
19041 if(bidmaps[i].first.length() > 0)
19042 bidmaps_cnt = i+1;
19043 }
19044
19045 //screen scripts
19046 void build_biscreens_list()
19047 {
19048 biscreens[0].first = "(None)";
19049 biscreens[0].second = -1;
19050 biscreens_cnt = 1;
19051
19052 for(int32_t i = 0; i < NUMSCRIPTSCREEN - 1; i++)
19053 {
19054 if(screenmap[i].scriptname.length()==0)
19055 continue;
19056
19057 stringstream ss;
19058 ss << screenmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19059 biscreens[biscreens_cnt].first = ss.str();
19060 biscreens[biscreens_cnt].second = i;
19061 biscreens_cnt++;
19062 }
19063
19064 // Blank out the rest of the list
19065 for(int32_t i=biscreens_cnt; i<NUMSCRIPTSCREEN; i++)
19066 {
19067 biscreens[i].first="";
19068 biscreens[i].second=-1;
19069 }
19070
19071 //Bubble sort! (doesn't account for gaps between scripts)
19072 for(int32_t i = 0; i < biscreens_cnt - 1; i++)
19073 {
19074 for(int32_t j = i + 1; j < biscreens_cnt; j++)
19075 {
19076 if(stricmp(biscreens[i].first.c_str(),biscreens[j].first.c_str()) > 0 && strcmp(biscreens[j].first.c_str(),""))
19077 zc_swap(biscreens[i],biscreens[j]);
19078 }
19079 }
19080
19081 biscreens_cnt = 0;
19082
19083 for(int32_t i = 0; i < NUMSCRIPTSCREEN; i++)
19084 if(biscreens[i].first.length() > 0)
19085 biscreens_cnt = i+1;
19086 }
19087
19088 //screen scripts
19089 void build_biitemsprites_list()
19090 {
19091 biditemsprites[0].first = "(None)";
19092 biditemsprites[0].second = -1;
19093 biitemsprites_cnt = 1;
19094
19095 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE - 1; i++)
19096 {
19097 if(itemspritemap[i].scriptname.length()==0)
19098 continue;
19099
19100 stringstream ss;
19101 ss << itemspritemap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19102 biditemsprites[biitemsprites_cnt].first = ss.str();
19103 biditemsprites[biitemsprites_cnt].second = i;
19104 biitemsprites_cnt++;
19105 }
19106
19107 // Blank out the rest of the list
19108 for(int32_t i=biitemsprites_cnt; i<NUMSCRIPTSITEMSPRITE; i++)
19109 {
19110 biditemsprites[i].first="";
19111 biditemsprites[i].second=-1;
19112 }
19113
19114 //Bubble sort! (doesn't account for gaps between scripts)
19115 for(int32_t i = 0; i < biitemsprites_cnt - 1; i++)
19116 {
19117 for(int32_t j = i + 1; j < biitemsprites_cnt; j++)
19118 {
19119 if(stricmp(biditemsprites[i].first.c_str(),biditemsprites[j].first.c_str()) > 0 && strcmp(biditemsprites[j].first.c_str(),""))
19120 zc_swap(biditemsprites[i],biditemsprites[j]);
19121 }
19122 }
19123
19124 biitemsprites_cnt = 0;
19125
19126 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE; i++)
19127 if(biditemsprites[i].first.length() > 0)
19128 biitemsprites_cnt = i+1;
19129 }
19130
19131 6 void build_biitems_list()
19132 {
19133 6 biitems[0].first = "(None)";
19134 6 biitems[0].second = -1;
19135 6 biitems_cnt = 1;
19136
19137
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTITEM - 1; i++, biitems_cnt++)
19138 {
19139 1530 stringstream ss;
19140
19141
4/6
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1530 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 1517 times.
1530 if(!itemmap[i].isEmpty())
19142
5/10
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 13 times.
✗ Branch 9 not taken.
13 ss << itemmap[i].scriptname << " (" << i+1 << ")";
19143
19144
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 biitems[biitems_cnt].first = ss.str();
19145 1530 biitems[biitems_cnt].second = i;
19146 1530 }
19147
19148
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < biitems_cnt - 1; i++)
19149 {
19150
2/2
✓ Branch 0 taken 195840 times.
✓ Branch 1 taken 1530 times.
197370 for(int32_t j = i + 1; j < biitems_cnt; j++)
19151 {
19152
4/4
✓ Branch 0 taken 4760 times.
✓ Branch 1 taken 191080 times.
✓ Branch 2 taken 4757 times.
✓ Branch 3 taken 3 times.
195840 if(stricmp(biitems[i].first.c_str(), biitems[j].first.c_str()) > 0 && strcmp(biitems[j].first.c_str(),""))
19153 3 zc_swap(biitems[i], biitems[j]);
19154 195840 }
19155 1530 }
19156
19157 6 biitems_cnt = 0;
19158
19159
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i = 0; i < NUMSCRIPTITEM; i++)
19160
2/2
✓ Branch 0 taken 1517 times.
✓ Branch 1 taken 19 times.
1555 if(biitems[i].first.length() > 0)
19161 19 biitems_cnt = i+1;
19162 6 }
19163
19164
19165 //dmap scripts
19166 void build_bidcomboscripts_list()
19167 {
19168 bidcomboscripts[0].first = "(None)";
19169 bidcomboscripts[0].second = -1;
19170 bidcomboscripts_cnt = 1;
19171
19172 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA - 1; i++)
19173 {
19174 if(comboscriptmap[i].scriptname.length()==0)
19175 continue;
19176
19177 stringstream ss;
19178 ss << comboscriptmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19179 bidcomboscripts[bidcomboscripts_cnt].first = ss.str();
19180 bidcomboscripts[bidcomboscripts_cnt].second = i;
19181 bidcomboscripts_cnt++;
19182 }
19183
19184 // Blank out the rest of the list
19185 for(int32_t i=bidcomboscripts_cnt; i<NUMSCRIPTSCOMBODATA; i++)
19186 {
19187 bidcomboscripts[i].first="";
19188 bidcomboscripts[i].second=-1;
19189 }
19190
19191 //Bubble sort! (doesn't account for gaps between scripts)
19192 for(int32_t i = 0; i < bidcomboscripts_cnt - 1; i++)
19193 {
19194 for(int32_t j = i + 1; j < bidcomboscripts_cnt; j++)
19195 {
19196 if(stricmp(bidcomboscripts[i].first.c_str(),bidcomboscripts[j].first.c_str()) > 0 && strcmp(bidcomboscripts[j].first.c_str(),""))
19197 zc_swap(bidcomboscripts[i],bidcomboscripts[j]);
19198 }
19199 }
19200
19201 bidcomboscripts_cnt = 0;
19202
19203 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA; i++)
19204 if(bidcomboscripts[i].first.length() > 0)
19205 bidcomboscripts_cnt = i+1;
19206 }
19207
19208
19209 const char *globalscriptlist(int32_t index, int32_t *list_size)
19210 {
19211 if(index < 0)
19212 {
19213 *list_size = biglobal_cnt;
19214 return NULL;
19215 }
19216
19217 return biglobal[index].first.c_str();
19218 }
19219
19220 const char *ffscriptlist(int32_t index, int32_t *list_size)
19221 {
19222 if(index < 0)
19223 {
19224 *list_size = biffs_cnt;
19225 return NULL;
19226 }
19227
19228 return biffs[index].first.c_str();
19229 }
19230
19231 const char *playerscriptlist(int32_t index, int32_t *list_size)
19232 {
19233 if(index < 0)
19234 {
19235 *list_size = bihero_cnt;
19236 return NULL;
19237 }
19238
19239 return bihero[index].first.c_str();
19240 }
19241
19242 const char *lweaponscriptlist(int32_t index, int32_t *list_size)
19243 {
19244 if(index < 0)
19245 {
19246 *list_size = bilweapons_cnt;
19247 return NULL;
19248 }
19249
19250 return bilweapons[index].first.c_str();
19251 }
19252
19253 const char *npcscriptlist(int32_t index, int32_t *list_size)
19254 {
19255 if(index < 0)
19256 {
19257 *list_size = binpcs_cnt;
19258 return NULL;
19259 }
19260
19261 return binpcs[index].first.c_str();
19262 }
19263
19264 static char itemscript_str_buf[32];
19265
19266 char *itemscriptlist(int32_t index, int32_t *list_size)
19267 {
19268 if(index>=0)
19269 {
19270 bound(index,0,255);
19271 sprintf(itemscript_str_buf,"%d: %s",index, ffcmap[index-1].scriptname.c_str());
19272 return itemscript_str_buf;
19273 }
19274
19275 *list_size=256;
19276 return NULL;
19277 }
19278
19279 static char ffscript_str_buf2[32];
19280
19281 const char *ffscriptlist2(int32_t index, int32_t *list_size)
19282 {
19283 if(index>=0)
19284 {
19285 char buf[20];
19286 bound(index,0,510);
19287
19288 if(ffcmap[index].scriptname=="")
19289 strcpy(buf, "<none>");
19290 else
19291 {
19292 strncpy(buf, ffcmap[index].scriptname.c_str(), 19);
19293 buf[19]='\0';
19294 }
19295
19296 sprintf(ffscript_str_buf2,"%d: %s",index+1, buf);
19297 return ffscript_str_buf2;
19298 }
19299
19300 *list_size=511;
19301 return NULL;
19302 }
19303
19304 static char itemscript_str_buf2[32];
19305
19306 const char *itemscriptlist2(int32_t index, int32_t *list_size)
19307 {
19308 if(index>=0)
19309 {
19310 char buf[20];
19311 bound(index,0,254);
19312
19313 if(itemmap[index].scriptname=="")
19314 strcpy(buf, "<none>");
19315 else
19316 {
19317 strncpy(buf, itemmap[index].scriptname.c_str(), 19);
19318 buf[19]='\0';
19319 }
19320
19321 sprintf(itemscript_str_buf2,"%d: %s",index+1, buf);
19322 return itemscript_str_buf2;
19323 }
19324
19325 *list_size=255;
19326 return NULL;
19327 }
19328
19329
19330 static char comboscript_str_buf2[32];
19331 const char *comboscriptlist2(int32_t index, int32_t *list_size)
19332 {
19333 if(index>=0)
19334 {
19335 char buf[20];
19336 bound(index,0,254);
19337
19338 if(comboscriptmap[index].scriptname=="")
19339 strcpy(buf, "<none>");
19340 else
19341 {
19342 strncpy(buf, comboscriptmap[index].scriptname.c_str(), 19);
19343 buf[19]='\0';
19344 }
19345
19346 sprintf(comboscript_str_buf2,"%d: %s",index+1, buf);
19347 return comboscript_str_buf2;
19348 }
19349
19350 *list_size=255;
19351 return NULL;
19352 }
19353
19354 static char gscript_str_buf2[40];
19355
19356 const char *gscriptlist2(int32_t index, int32_t *list_size)
19357 {
19358 if(index >= 0)
19359 {
19360 bound(index,0,3);
19361
19362 char buf[20];
19363
19364 if(globalmap[index].scriptname == "")
19365 strcpy(buf, "<none>");
19366 else
19367 {
19368 strncpy(buf, globalmap[index].scriptname.c_str(), 19);
19369 buf[19]='\0';
19370 }
19371
19372 switch(index)
19373 {
19374 case GLOBAL_SCRIPT_INIT:
19375 sprintf(gscript_str_buf2,"Initialization: %s", buf); break;
19376 case GLOBAL_SCRIPT_GAME:
19377 sprintf(gscript_str_buf2,"Active: %s", buf); break;
19378 case GLOBAL_SCRIPT_END:
19379 sprintf(gscript_str_buf2,"onExit: %s", buf); break;
19380 case GLOBAL_SCRIPT_ONSAVELOAD:
19381 sprintf(gscript_str_buf2,"onSaveLoad: %s", buf); break;
19382 case GLOBAL_SCRIPT_ONLAUNCH:
19383 sprintf(gscript_str_buf2,"onLaunch: %s", buf); break;
19384 case GLOBAL_SCRIPT_ONCONTGAME:
19385 sprintf(gscript_str_buf2,"onContGame: %s", buf); break;
19386 case GLOBAL_SCRIPT_F6:
19387 sprintf(gscript_str_buf2,"onF6Menu: %s", buf); break;
19388 case GLOBAL_SCRIPT_ONSAVE:
19389 sprintf(gscript_str_buf2,"onSave: %s", buf); break;
19390 }
19391
19392 return gscript_str_buf2;
19393 }
19394
19395 if(list_size != NULL)
19396 *list_size=4;
19397
19398 return NULL;
19399 }
19400
19401 static int32_t as_ffc_list[] = { 4, 5, 6, -1};
19402 static int32_t as_global_list[] = { 7, 8, 9, -1}; //Why does putting 15 in here not place my message only on the global tab? ~Joe
19403 static int32_t as_item_list[] = { 10, 11, 12, -1};
19404 static int32_t as_npc_list[] = { 18, 19, 20, -1}; //npc scripts TAB
19405 static int32_t as_lweapon_list[] = { 21, 22, 23, -1}; //lweapon scripts TAB
19406 static int32_t as_eweapon_list[] = { 24, 25, 26, -1}; //eweapon scripts TAB
19407 static int32_t as_hero_list[] = { 27, 28, 29, -1}; //hero scripts TAB
19408 static int32_t as_screen_list[] = { 30, 31, 32, -1}; //screendata scripts TAB
19409 static int32_t as_dmap_list[] = { 33, 34, 35, -1}; //dmapdata scripts TAB
19410 static int32_t as_itemsprite_list[] = { 36, 37, 38, -1}; //dmapdata scripts TAB
19411 static int32_t as_comboscript_list[] = { 39, 40, 41, -1}; //combodata scripts TAB
19412 static int32_t as_genericscript_list[] = { 45, 46, 47, -1}; //generic scripts TAB
19413 static int32_t as_subscreenscript_list[] = { 48, 49, 50, -1}; //generic scripts TAB
19414
19415 static TABPANEL assignscript_tabs[] =
19416 {
19417 // (text)
19418 { (char *)"FFC", D_SELECTED, as_ffc_list, 0, NULL },
19419 { (char *)"Global", 0, as_global_list, 0, NULL },
19420 { (char *)"Item", 0, as_item_list, 0, NULL },
19421 { (char *)"NPC", 0, as_npc_list, 0, NULL },
19422 { (char *)"LWeapon", 0, as_lweapon_list, 0, NULL },
19423 { (char *)"EWeapon", 0, as_eweapon_list, 0, NULL },
19424 { (char *)"Hero", 0, as_hero_list, 0, NULL },
19425 { (char *)"DMap", 0, as_dmap_list, 0, NULL },
19426 { (char *)"Screen", 0, as_screen_list, 0, NULL },
19427 { (char *)"Item Sprite", 0, as_itemsprite_list, 0, NULL },
19428 { (char *)"Combo", 0, as_comboscript_list, 0, NULL },
19429 { (char *)"Generic", 0, as_genericscript_list, 0, NULL },
19430 { (char *)"Subscreen", 0, as_subscreenscript_list, 0, NULL },
19431 { NULL, 0, NULL, 0, NULL }
19432 };
19433
19434 const char *assignffclist(int32_t index, int32_t *list_size)
19435 {
19436 if(index<0)
19437 {
19438 *list_size = (int32_t)ffcmap.size();
19439 return NULL;
19440 }
19441
19442 return ffcmap[index].output.c_str();
19443 }
19444
19445 const char *assigngloballist(int32_t index, int32_t *list_size)
19446 {
19447 if(index<0)
19448 {
19449 *list_size = (int32_t)globalmap.size();
19450 return NULL;
19451 }
19452
19453 return globalmap[index].output.c_str();
19454 }
19455
19456 const char *assigncombolist(int32_t index, int32_t *list_size)
19457 {
19458 if(index<0)
19459 {
19460 *list_size = (int32_t)comboscriptmap.size();
19461 return NULL;
19462 }
19463
19464 return comboscriptmap[index].output.c_str();
19465 }
19466
19467 const char *assigngenericlist(int32_t index, int32_t *list_size)
19468 {
19469 if(index<0)
19470 {
19471 *list_size = ((int32_t)genericmap.size());
19472 return NULL;
19473 }
19474
19475 return genericmap[index].output.c_str();
19476 }
19477
19478 const char *assignsubscreenlist(int32_t index, int32_t *list_size)
19479 {
19480 if(index<0)
19481 {
19482 *list_size = ((int32_t)subscreenmap.size());
19483 return NULL;
19484 }
19485
19486 return subscreenmap[index].output.c_str();
19487 }
19488
19489 const char *assignitemlist(int32_t index, int32_t *list_size)
19490 {
19491 if(index<0)
19492 {
19493 *list_size = (int32_t)itemmap.size();
19494 return NULL;
19495 }
19496
19497 return itemmap[index].output.c_str();
19498 }
19499 const char *assignnpclist(int32_t index, int32_t *list_size)
19500 {
19501 if(index<0)
19502 {
19503 *list_size = (int32_t)npcmap.size();
19504 return NULL;
19505 }
19506
19507 return npcmap[index].output.c_str();
19508 }
19509
19510 const char *assignlweaponlist(int32_t index, int32_t *list_size)
19511 {
19512 if(index<0)
19513 {
19514 *list_size = (int32_t)lwpnmap.size();
19515 return NULL;
19516 }
19517
19518 return lwpnmap[index].output.c_str();
19519 }
19520
19521 const char *assigneweaponlist(int32_t index, int32_t *list_size)
19522 {
19523 if(index<0)
19524 {
19525 *list_size = (int32_t)ewpnmap.size();
19526 return NULL;
19527 }
19528
19529 return ewpnmap[index].output.c_str();
19530 }
19531
19532 const char *assignplayerlist(int32_t index, int32_t *list_size)
19533 {
19534 if(index<0)
19535 {
19536 *list_size = (int32_t)playermap.size();
19537 return NULL;
19538 }
19539
19540 return playermap[index].output.c_str();
19541 }
19542
19543 const char *assigndmaplist(int32_t index, int32_t *list_size)
19544 {
19545 if(index<0)
19546 {
19547 *list_size = (int32_t)dmapmap.size();
19548 return NULL;
19549 }
19550
19551 return dmapmap[index].output.c_str();
19552 }
19553
19554 const char *assignscreenlist(int32_t index, int32_t *list_size)
19555 {
19556 if(index<0)
19557 {
19558 *list_size = (int32_t)screenmap.size();
19559 return NULL;
19560 }
19561
19562 return screenmap[index].output.c_str();
19563 }
19564
19565 const char *assignitemspritelist(int32_t index, int32_t *list_size)
19566 {
19567 if(index<0)
19568 {
19569 *list_size = (int32_t)itemspritemap.size();
19570 return NULL;
19571 }
19572
19573 return itemspritemap[index].output.c_str();
19574 }
19575
19576 const char *assignffcscriptlist(int32_t index, int32_t *list_size)
19577 {
19578 if(index<0)
19579 {
19580 *list_size = (int32_t)asffcscripts.size();
19581 return NULL;
19582 }
19583
19584 return asffcscripts[index].c_str();
19585 }
19586
19587 const char *assignglobalscriptlist(int32_t index, int32_t *list_size)
19588 {
19589 if(index<0)
19590 {
19591 *list_size = (int32_t)asglobalscripts.size();
19592 return NULL;
19593 }
19594
19595 return asglobalscripts[index].c_str();
19596 }
19597
19598 const char *assignitemscriptlist(int32_t index, int32_t *list_size)
19599 {
19600 if(index<0)
19601 {
19602 *list_size = (int32_t)asitemscripts.size();
19603 return NULL;
19604 }
19605
19606 return asitemscripts[index].c_str();
19607 }
19608
19609 const char *assignnpcscriptlist(int32_t index, int32_t *list_size)
19610 {
19611 if(index<0)
19612 {
19613 *list_size = (int32_t)asnpcscripts.size();
19614 return NULL;
19615 }
19616
19617 return asnpcscripts[index].c_str();
19618 }
19619
19620 const char *assignlweaponscriptlist(int32_t index, int32_t *list_size)
19621 {
19622 if(index<0)
19623 {
19624 *list_size = (int32_t)aslweaponscripts.size();
19625 return NULL;
19626 }
19627
19628 return aslweaponscripts[index].c_str();
19629 }
19630
19631 const char *assigneweaponscriptlist(int32_t index, int32_t *list_size)
19632 {
19633 if(index<0)
19634 {
19635 *list_size = (int32_t)aseweaponscripts.size();
19636 return NULL;
19637 }
19638
19639 return aseweaponscripts[index].c_str();
19640 }
19641
19642 const char *assignplayerscriptlist(int32_t index, int32_t *list_size)
19643 {
19644 if(index<0)
19645 {
19646 *list_size = (int32_t)asplayerscripts.size();
19647 return NULL;
19648 }
19649
19650 return asplayerscripts[index].c_str();
19651 }
19652
19653 const char *assigndmapscriptlist(int32_t index, int32_t *list_size)
19654 {
19655 if(index<0)
19656 {
19657 *list_size = (int32_t)asdmapscripts.size();
19658 return NULL;
19659 }
19660
19661 return asdmapscripts[index].c_str();
19662 }
19663
19664 const char *assignscreenscriptlist(int32_t index, int32_t *list_size)
19665 {
19666 if(index<0)
19667 {
19668 *list_size = (int32_t)asscreenscripts.size();
19669 return NULL;
19670 }
19671
19672 return asscreenscripts[index].c_str();
19673 }
19674
19675 const char *assignitemspritescriptlist(int32_t index, int32_t *list_size)
19676 {
19677 if(index<0)
19678 {
19679 *list_size = (int32_t)asitemspritescripts.size();
19680 return NULL;
19681 }
19682
19683 return asitemspritescripts[index].c_str();
19684 }
19685
19686 const char *assigncomboscriptlist(int32_t index, int32_t *list_size)
19687 {
19688 if(index<0)
19689 {
19690 *list_size = (int32_t)ascomboscripts.size();
19691 return NULL;
19692 }
19693
19694 return ascomboscripts[index].c_str();
19695 }
19696
19697 const char *assigngenericscriptlist(int32_t index, int32_t *list_size)
19698 {
19699 if(index<0)
19700 {
19701 *list_size = (int32_t)asgenericscripts.size();
19702 return NULL;
19703 }
19704
19705 return asgenericscripts[index].c_str();
19706 }
19707
19708 const char *assignsubscreenscriptlist(int32_t index, int32_t *list_size)
19709 {
19710 if(index<0)
19711 {
19712 *list_size = (int32_t)assubscreenscripts.size();
19713 return NULL;
19714 }
19715
19716 return assubscreenscripts[index].c_str();
19717 }
19718
19719 12 static ListData assignffc_list(assignffclist, &font);
19720 12 static ListData assignffcscript_list(assignffcscriptlist, &font);
19721 12 static ListData assignglobal_list(assigngloballist, &font);
19722 12 static ListData assignglobalscript_list(assignglobalscriptlist, &font);
19723 12 static ListData assignitem_list(assignitemlist, &font);
19724 12 static ListData assignitemscript_list(assignitemscriptlist, &font);
19725 12 static ListData assignnpc_list(assignnpclist, &font);
19726 12 static ListData assignnpcscript_list(assignnpcscriptlist, &font);
19727 12 static ListData assignlweapon_list(assignlweaponlist, &font);
19728 12 static ListData assignlweaponscript_list(assignlweaponscriptlist, &font);
19729 12 static ListData assigneweapon_list(assigneweaponlist, &font);
19730 12 static ListData assigneweaponscript_list(assigneweaponscriptlist, &font);
19731
19732 12 static ListData assignplayer_list(assignplayerlist, &font);
19733 12 static ListData assignplayerscript_list(assignplayerscriptlist, &font);
19734
19735 12 static ListData assigndmap_list(assigndmaplist, &font);
19736 12 static ListData assigndmapscript_list(assigndmapscriptlist, &font);
19737
19738 12 static ListData assignscreen_list(assignscreenlist, &font);
19739 12 static ListData assignscreenscript_list(assignscreenscriptlist, &font);
19740
19741 12 static ListData assignitemsprite_list(assignitemspritelist, &font);
19742 12 static ListData assignitemspritescript_list(assignitemspritescriptlist, &font);
19743
19744 12 static ListData assigncombo_list(assigncombolist, &font);
19745 12 static ListData assigncomboscript_list(assigncomboscriptlist, &font);
19746
19747 12 static ListData assigngeneric_list(assigngenericlist, &font);
19748 12 static ListData assigngenericscript_list(assigngenericscriptlist, &font);
19749
19750 12 static ListData assignsubscreen_list(assignsubscreenlist, &font);
19751 12 static ListData assignsubscreenscript_list(assignsubscreenscriptlist, &font);
19752
19753 static DIALOG assignscript_dlg[] =
19754 {
19755 // x y w h fg bg key flags d1 d2 dp
19756 12 { jwin_win_proc, 0, 0, 330, 236, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Assign Compiled Script", NULL, NULL },
19757 12 { jwin_tab_proc, 6, 25, 330-12, 130, 0, 0, 0, 0, 0, 0, assignscript_tabs, NULL, (void*)assignscript_dlg },
19758 12 { jwin_button_proc, 251, 207, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
19759 12 { jwin_button_proc, 182, 207, 61, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
19760 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignffc_list, NULL, NULL },
19761 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignffcscript_list, NULL, NULL },
19762 //6
19763 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19764 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignglobal_list, NULL, NULL },
19765 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignglobalscript_list, NULL, NULL },
19766 //9
19767 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19768 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitem_list, NULL, NULL },
19769 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemscript_list, NULL, NULL },
19770 //12
19771 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19772 //13
19773 12 { jwin_check_proc, 22, 211, 90, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Output ZASM code to allegro.log", NULL, NULL },
19774 12 { jwin_text_proc, 22, 178, 90, 24, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19775 12 { d_dummy_proc, 0, 0, 0, 0, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19776 //16
19777 12 { d_dummy_proc, 0, 0, 0, 0, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19778 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
19779 //npc scripts
19780 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignnpc_list, NULL, NULL },
19781 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignnpcscript_list, NULL, NULL },
19782 //20
19783 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19784 //21
19785 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignlweapon_list, NULL, NULL },
19786 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignlweaponscript_list, NULL, NULL },
19787 //23
19788 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19789 //24
19790 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigneweapon_list, NULL, NULL },
19791 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigneweaponscript_list, NULL, NULL },
19792 //26
19793 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19794 //27
19795 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignplayer_list, NULL, NULL },
19796 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignplayerscript_list, NULL, NULL },
19797 //29
19798 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19799 //30
19800 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignscreen_list, NULL, NULL },
19801 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignscreenscript_list, NULL, NULL },
19802 //32
19803 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19804 //33
19805 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigndmap_list, NULL, NULL },
19806 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigndmapscript_list, NULL, NULL },
19807 //35
19808 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19809 //36
19810 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemsprite_list, NULL, NULL },
19811 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemspritescript_list, NULL, NULL },
19812 //38
19813 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19814
19815 //39
19816 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigncombo_list, NULL, NULL },
19817 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigncomboscript_list, NULL, NULL },
19818 //41
19819 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19820 12 { jwin_button_proc, 78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Info", NULL, NULL },
19821 12 { jwin_button_proc, 174+78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Info", NULL, NULL },
19822 12 { jwin_button_proc, 87+78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Clear", NULL, NULL },
19823 //45
19824 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigngeneric_list, NULL, NULL },
19825 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigngenericscript_list, NULL, NULL },
19826 //47
19827 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19828 //48
19829 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignsubscreen_list, NULL, NULL },
19830 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignsubscreenscript_list, NULL, NULL },
19831 //50
19832 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19833 12 { jwin_check_proc, 22, 221, 90, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "...And output ZASM comments", NULL, NULL },
19834
19835 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
19836
19837 };
19838
19839 int32_t txtout(BITMAP* dest, const char* txt, int32_t x, int32_t y, bool disabled)
19840 {
19841 if(disabled)
19842 {
19843 gui_textout_ln(dest, font, (uint8_t*)txt, x+1, y+1, scheme[jcLIGHT], scheme[jcBOX], 0);
19844 return gui_textout_ln(dest, font, (uint8_t*)txt, x, y, scheme[jcMEDDARK], -1, 0);
19845 }
19846 else
19847 {
19848 return gui_textout_ln(dest, font, (uint8_t*)txt, x, y, scheme[jcBOXFG], scheme[jcBOX], 0);
19849 }
19850 }
19851
19852 int32_t jwin_zmeta_proc(int32_t msg, DIALOG *d, int32_t )
19853 {
19854 int32_t ret = D_O_K;
19855 ASSERT(d);
19856
19857 BITMAP* target = (msg==MSG_START ? NULL : screen);
19858 switch(msg)
19859 {
19860 case MSG_START:
19861 case MSG_DRAW:
19862 {
19863 FONT *oldfont = font;
19864
19865 if(d->dp2)
19866 {
19867 font = (FONT*)d->dp2;
19868 }
19869
19870 bool disabled = (d->flags & D_DISABLED) != 0;
19871 if(d->dp)
19872 {
19873 zasm_meta const& meta = *((zasm_meta*)d->dp);
19874 int32_t ind = -1;
19875 d->w = 0;
19876 if(!meta.valid())
19877 {
19878 d->w = txtout(target, "Invalid ZASM metadata found!", d->x, d->y, disabled);
19879 ++ind;
19880 }
19881
19882 int32_t t_w = 0;
19883 char buf[1024];
19884 memset(buf, 0, sizeof(buf));
19885 sprintf(buf, "ZASM Version: %d", meta.zasm_v);
19886 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19887 d->w = zc_max(d->w, t_w);
19888 memset(buf, 0, sizeof(buf));
19889 sprintf(buf, "Metadata Version: %d", meta.meta_v);
19890 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19891 d->w = zc_max(d->w, t_w);
19892 memset(buf, 0, sizeof(buf));
19893 sprintf(buf, "FFScript Version: %d", meta.ffscript_v);
19894 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19895 d->w = zc_max(d->w, t_w);
19896 memset(buf, 0, sizeof(buf));
19897 sprintf(buf, "Script Name: %s", meta.script_name.c_str());
19898 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19899 d->w = zc_max(d->w, t_w);
19900 memset(buf, 0, sizeof(buf));
19901 sprintf(buf, "Author: %s", meta.author.c_str());
19902 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19903 d->w = zc_max(d->w, t_w);
19904 memset(buf, 0, sizeof(buf));
19905 sprintf(buf, "Script Type: %s", get_script_name(meta.script_type).c_str());
19906 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19907 d->w = zc_max(d->w, t_w);
19908 for(auto q = 0; q < 4; ++q)
19909 {
19910 if(!meta.attributes[q].size())
19911 continue;
19912 memset(buf, 0, sizeof(buf));
19913 sprintf(buf, "Attributes[%d]: %s", q, meta.attributes[q].c_str());
19914 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19915 d->w = zc_max(d->w, t_w);
19916 }
19917 for(auto q = 0; q < 8; ++q)
19918 {
19919 if(!meta.attribytes[q].size())
19920 continue;
19921 memset(buf, 0, sizeof(buf));
19922 sprintf(buf, "Attribytes[%d]: %s", q, meta.attribytes[q].c_str());
19923 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19924 d->w = zc_max(d->w, t_w);
19925 }
19926 for(auto q = 0; q < 8; ++q)
19927 {
19928 if(!meta.attrishorts[q].size())
19929 continue;
19930 memset(buf, 0, sizeof(buf));
19931 sprintf(buf, "Attrishorts[%d]: %s", q, meta.attrishorts[q].c_str());
19932 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19933 d->w = zc_max(d->w, t_w);
19934 }
19935 bool indentrun = false;
19936 int32_t run_indent = txtout(NULL, "void run(", 0, 0, false);
19937 std::ostringstream oss;
19938 oss << "void run(";
19939 for(int32_t q = 0; q < 8; ++q)
19940 {
19941 if(!meta.run_idens[q].size() || meta.run_types[q] == ZMETA_NULL_TYPE) continue;
19942 if(q > 0)
19943 oss << ", ";
19944 string type_name = ZScript::getDataTypeName(meta.run_types[q]);
19945 lowerstr(type_name); //all lowercase for this output
19946 if(oss.str().size() > unsigned(indentrun ? 41 : 50))
19947 {
19948 memset(buf, 0, sizeof(buf));
19949 sprintf(buf, "%s", oss.str().c_str());
19950 t_w = txtout(target, buf, d->x + (indentrun ? run_indent : 0), d->y + ((++ind)*(text_height(font) + 3)), disabled) + (indentrun ? run_indent : 0);
19951 d->w = zc_max(d->w, t_w);
19952 oss.str("");
19953 indentrun = true;
19954 }
19955 oss << type_name.c_str() << " " << meta.run_idens[q];
19956 }
19957 oss << ");";
19958 memset(buf, 0, sizeof(buf));
19959 sprintf(buf, "%s", oss.str().c_str());
19960 t_w = txtout(target, buf, d->x + (indentrun ? run_indent : 0), d->y + ((++ind)*(text_height(font) + 3)), disabled) + (indentrun ? run_indent : 0);
19961 d->w = zc_max(d->w, t_w);
19962 memset(buf, 0, sizeof(buf));
19963 sprintf(buf, "Compiler Version: %d.%d.%d.%d", meta.compiler_v1, meta.compiler_v2, meta.compiler_v3, meta.compiler_v4);
19964 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19965 d->w = zc_max(d->w, t_w);
19966 memset(buf, 0, sizeof(buf));
19967 sprintf(buf, "Parser-generated: %s", (meta.flags & ZMETA_AUTOGEN)!=0 ? "TRUE" : "FALSE");
19968 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19969 d->w = zc_max(d->w, t_w);
19970 d->h = (++ind) * (text_height(font) + 3) -3;
19971 }
19972 else
19973 {
19974 d->w = txtout(target, "No ZASM metadata found!", d->x, d->y, disabled);
19975 d->h = text_height(font);
19976 }
19977
19978 if(d->dp3) //function trigger
19979 {
19980 typedef void (*funcType)(void);
19981 funcType func=reinterpret_cast<funcType>(d->dp3);
19982 func();
19983 }
19984
19985 font = oldfont;
19986 break;
19987 }
19988 }
19989
19990 return ret;
19991 }
19992
19993 void resize_scriptinfo_dlg();
19994
19995 static DIALOG scriptinfo_dlg[] =
19996 {
19997 // x y w h fg bg key flags d1 d2 dp
19998 { jwin_win_proc, 0, 0, 200, 150, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Metadata", NULL, NULL },
19999 { d_dummy_proc, 6, 25, 330-12, 130, 0, 0, 0, 0, 0, 0, assignscript_tabs, NULL, NULL },
20000 { jwin_button_proc, 70, 120, 60, 20, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
20001 { jwin_zmeta_proc, 50, 30, 100, 100, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, (void*)resize_scriptinfo_dlg },
20002
20003 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
20004 };
20005
20006 void resize_scriptinfo_dlg()
20007 {
20008 DIALOG *meta_proc = &scriptinfo_dlg[3], *window = &scriptinfo_dlg[0], *ok_button = &scriptinfo_dlg[2];
20009 int32_t bmargin = 15, hmargins = 30;
20010 jwin_ulalign_dialog(scriptinfo_dlg);
20011 window->w = hmargins*2 + meta_proc->w;
20012 meta_proc->x = hmargins;
20013 window->h = meta_proc->y + meta_proc->h + ok_button->h + bmargin*2;
20014 ok_button->x = (window->w/2)-(ok_button->w/2);
20015 ok_button->y = meta_proc->y + meta_proc->h + bmargin;
20016 jwin_center_dialog(scriptinfo_dlg);
20017 }
20018
20019 void showScriptInfo(zasm_meta const* meta)
20020 {
20021 scriptinfo_dlg[3].dp = (void*)meta;
20022 scriptinfo_dlg[0].dp2 = get_zc_font(font_lfont);
20023 large_dialog(scriptinfo_dlg);
20024 jwin_zmeta_proc(MSG_START,&scriptinfo_dlg[3],0); //Calculate size before calling dialog
20025 jwin_center_dialog(scriptinfo_dlg);
20026 do_zqdialog(scriptinfo_dlg,2);
20027 }
20028
20029 void write_includepaths();
20030 void call_compile_settings();
20031 int32_t onZScriptCompilerSettings()
20032 {
20033 call_compile_settings();
20034 return D_O_K;
20035 }
20036
20037 void doEditZScript()
20038 {
20039 if(do_box_edit(zScript, "ZScript Buffer", false, false))
20040 saved=false;
20041 }
20042
20043 std::string qst_cfg_header_from_path(std::string path);
20044 extern char *filepath;
20045 string get_box_cfg_hdr(int num)
20046 {
20047 if(num)
20048 return "misc";
20049 return qst_cfg_header_from_path(filepath);
20050 }
20051
20052 //{ Start type-specific import dlgs
20053 12 static ListData ffscript_sel_dlg_list(ffscriptlist2, &font);
20054 12 static ListData itemscript_sel_dlg_list(itemscriptlist2, &font);
20055 12 static ListData comboscript_sel_dlg_list(comboscriptlist2, &font);
20056 12 static ListData gscript_sel_dlg_list(gscriptlist2, &font);
20057 static char npcscript_str_buf2[32];
20058 const char *npcscriptlist2(int32_t index, int32_t *list_size)
20059 {
20060 if(index>=0)
20061 {
20062 char buf[20];
20063 bound(index,0,254);
20064
20065 if(npcmap[index].scriptname=="")
20066 strcpy(buf, "<none>");
20067 else
20068 {
20069 strncpy(buf, npcmap[index].scriptname.c_str(), 19);
20070 buf[19]='\0';
20071 }
20072
20073 sprintf(npcscript_str_buf2,"%d: %s",index+1, buf);
20074 return npcscript_str_buf2;
20075 }
20076
20077 *list_size=(NUMSCRIPTGUYS-1);
20078 return NULL;
20079 }
20080 12 static ListData npcscript_sel_dlg_list(npcscriptlist2, &font);
20081 static char lweaponscript_str_buf2[32];
20082 const char *lweaponscriptlist2(int32_t index, int32_t *list_size)
20083 {
20084 if(index>=0)
20085 {
20086 char buf[20];
20087 bound(index,0,254);
20088
20089 if(lwpnmap[index].scriptname=="")
20090 strcpy(buf, "<none>");
20091 else
20092 {
20093 strncpy(buf, lwpnmap[index].scriptname.c_str(), 19);
20094 buf[19]='\0';
20095 }
20096
20097 sprintf(lweaponscript_str_buf2,"%d: %s",index+1, buf);
20098 return lweaponscript_str_buf2;
20099 }
20100
20101 *list_size=(NUMSCRIPTWEAPONS-1);
20102 return NULL;
20103 }
20104 12 static ListData lweaponscript_sel_dlg_list(lweaponscriptlist2, &font);
20105 static char eweaponscript_str_buf2[32];
20106 const char *eweaponscriptlist2(int32_t index, int32_t *list_size)
20107 {
20108 if(index>=0)
20109 {
20110 char buf[20];
20111 bound(index,0,254);
20112
20113 if(ewpnmap[index].scriptname=="")
20114 strcpy(buf, "<none>");
20115 else
20116 {
20117 strncpy(buf, ewpnmap[index].scriptname.c_str(), 19);
20118 buf[19]='\0';
20119 }
20120
20121 sprintf(eweaponscript_str_buf2,"%d: %s",index+1, buf);
20122 return eweaponscript_str_buf2;
20123 }
20124
20125 *list_size=(NUMSCRIPTWEAPONS-1);
20126 return NULL;
20127 }
20128 12 static ListData eweaponscript_sel_dlg_list(eweaponscriptlist2, &font);
20129 static char playerscript_str_buf2[32];
20130 const char *playerscriptlist2(int32_t index, int32_t *list_size)
20131 {
20132 if(index>=0)
20133 {
20134 char buf[20];
20135 bound(index,0,3);
20136
20137 if(playermap[index].scriptname=="")
20138 strcpy(buf, "<none>");
20139 else
20140 {
20141 strncpy(buf, playermap[index].scriptname.c_str(), 19);
20142 buf[19]='\0';
20143 }
20144
20145 if(index==0)
20146 sprintf(playerscript_str_buf2,"Init: %s", buf);
20147
20148 if(index==1)
20149 sprintf(playerscript_str_buf2,"Active: %s", buf);
20150
20151 if(index==2)
20152 sprintf(playerscript_str_buf2,"Death: %s", buf);
20153
20154
20155 //sprintf(playerscript_str_buf2,"%d: %s",index+1, buf);
20156 return playerscript_str_buf2;
20157 }
20158
20159 *list_size=(NUMSCRIPTHERO-1);
20160 return NULL;
20161 }
20162 static char itemspritescript_str_buf2[32];
20163 const char *itemspritescriptlist2(int32_t index, int32_t *list_size)
20164 {
20165 if(index>=0)
20166 {
20167 char buf[20];
20168 bound(index,0,254);
20169
20170 if(itemspritemap[index].scriptname=="")
20171 strcpy(buf, "<none>");
20172 else
20173 {
20174 strncpy(buf, itemspritemap[index].scriptname.c_str(), 19);
20175 buf[19]='\0';
20176 }
20177
20178 sprintf(itemspritescript_str_buf2,"%d: %s",index+1, buf);
20179 return itemspritescript_str_buf2;
20180 }
20181
20182 *list_size=(NUMSCRIPTSITEMSPRITE-1);
20183 return NULL;
20184 }
20185 12 static ListData playerscript_sel_dlg_list(playerscriptlist2, &font);
20186 static char dmapscript_str_buf2[32];
20187 const char *dmapscriptlist2(int32_t index, int32_t *list_size)
20188 {
20189 if(index>=0)
20190 {
20191 char buf[20];
20192 bound(index,0,254);
20193
20194 if(dmapmap[index].scriptname=="")
20195 strcpy(buf, "<none>");
20196 else
20197 {
20198 strncpy(buf, dmapmap[index].scriptname.c_str(), 19);
20199 buf[19]='\0';
20200 }
20201
20202 sprintf(dmapscript_str_buf2,"%d: %s",index+1, buf);
20203 return dmapscript_str_buf2;
20204 }
20205
20206 *list_size=(NUMSCRIPTSDMAP-1);
20207 return NULL;
20208 }
20209 12 static ListData dmapscript_sel_dlg_list(dmapscriptlist2, &font);
20210 12 static ListData itemspritescript_sel_dlg_list(itemspritescriptlist2, &font);
20211 static char screenscript_str_buf2[32];
20212 const char *screenscriptlist2(int32_t index, int32_t *list_size)
20213 {
20214 if(index>=0)
20215 {
20216 char buf[20];
20217 bound(index,0,254);
20218
20219 if(screenmap[index].scriptname=="")
20220 strcpy(buf, "<none>");
20221 else
20222 {
20223 strncpy(buf, screenmap[index].scriptname.c_str(), 19);
20224 buf[19]='\0';
20225 }
20226
20227 sprintf(screenscript_str_buf2,"%d: %s",index+1, buf);
20228 return screenscript_str_buf2;
20229 }
20230
20231 *list_size=(NUMSCRIPTSCREEN-1);
20232 return NULL;
20233 }
20234 12 static ListData screenscript_sel_dlg_list(screenscriptlist2, &font);
20235 //} End type-specific import dlgs
20236
20237 6 void clear_map_states()
20238 {
20239
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(map<int32_t, script_slot_data>::iterator it = ffcmap.begin();
20240 3072 it != ffcmap.end(); ++it)
20241 {
20242 3066 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20243 3066 }
20244
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(map<int32_t, script_slot_data>::iterator it = globalmap.begin();
20245 54 it != globalmap.end(); ++it)
20246 {
20247 48 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20248 48 }
20249
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = itemmap.begin();
20250 1536 it != itemmap.end(); ++it)
20251 {
20252 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20253 1530 }
20254
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = npcmap.begin();
20255 1536 it != npcmap.end(); ++it)
20256 {
20257 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20258 1530 }
20259
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = ewpnmap.begin();
20260 1536 it != ewpnmap.end(); ++it)
20261 {
20262 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20263 1530 }
20264
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = lwpnmap.begin();
20265 1536 it != lwpnmap.end(); ++it)
20266 {
20267 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20268 1530 }
20269
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(map<int32_t, script_slot_data>::iterator it = playermap.begin();
20270 30 it != playermap.end(); ++it)
20271 {
20272 24 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20273 24 }
20274
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = dmapmap.begin();
20275 1536 it != dmapmap.end(); ++it)
20276 {
20277 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20278 1530 }
20279
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = screenmap.begin();
20280 1536 it != screenmap.end(); ++it)
20281 {
20282 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20283 1530 }
20284
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = itemspritemap.begin();
20285 1536 it != itemspritemap.end(); ++it)
20286 {
20287 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20288 1530 }
20289
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(map<int32_t, script_slot_data>::iterator it = comboscriptmap.begin();
20290 3072 it != comboscriptmap.end(); ++it)
20291 {
20292 3066 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20293 3066 }
20294 6 }
20295
20296 void clearAssignSlotDlg()
20297 {
20298 assignscript_dlg[0].dp2 = get_zc_font(font_lfont);
20299 assignscript_dlg[4].d1 = -1;
20300 assignscript_dlg[5].d1 = -1;
20301 assignscript_dlg[7].d1 = -1;
20302 assignscript_dlg[8].d1 = -1;
20303 assignscript_dlg[10].d1 = -1;
20304 assignscript_dlg[11].d1 = -1;
20305 assignscript_dlg[13].flags = 0;
20306 }
20307
20308 void inc_script_name(string& name)
20309 {
20310 size_t pos = name.find_last_not_of("0123456789");
20311 pos = name.find_first_of("0123456789",pos);
20312 std::ostringstream oss;
20313 if(pos == string::npos)
20314 {
20315 oss << name << 2;
20316 }
20317 else
20318 {
20319 int32_t val = atoi(name.substr(pos).c_str());
20320 oss << name.substr(0,pos) << val+1;
20321 }
20322 name = oss.str();
20323 }
20324
20325 enum script_slot_type
20326 {
20327 type_ffc, type_global, type_itemdata, type_npc, type_lweapon, type_eweapon,
20328 type_hero, type_dmap, type_screen, type_itemsprite, type_combo, type_generic,
20329 type_subscreen, num_types
20330 };
20331 script_slot_type getType(ScriptType type)
20332 {
20333 switch(type)
20334 {
20335 case ScriptType::FFC: return type_ffc;
20336 case ScriptType::Global: return type_global;
20337 case ScriptType::Item: return type_itemdata;
20338 case ScriptType::NPC: return type_npc;
20339 case ScriptType::Lwpn: return type_lweapon;
20340 case ScriptType::Ewpn: return type_eweapon;
20341 case ScriptType::Hero: return type_hero;
20342 case ScriptType::DMap:
20343 case ScriptType::ScriptedActiveSubscreen:
20344 case ScriptType::ScriptedPassiveSubscreen:
20345 case ScriptType::OnMap:
20346 return type_dmap;
20347 case ScriptType::Generic: case ScriptType::GenericFrozen:
20348 return type_generic;
20349 case ScriptType::Screen: return type_screen;
20350 case ScriptType::ItemSprite: return type_itemsprite;
20351 case ScriptType::Combo: return type_combo;
20352 case ScriptType::EngineSubscreen: return type_subscreen;
20353 default: return type_ffc; //Default
20354 }
20355 }
20356 #define SLOTMSGFLAG_MISSING 0x01
20357 #define SLOTMSG_SIZE 512
20358 bool checkSkip(int32_t format, byte flags)
20359 {
20360 switch(format)
20361 {
20362 case SCRIPT_FORMAT_DEFAULT:
20363 return (flags != 0);
20364 case SCRIPT_FORMAT_INVALID:
20365 return ((flags & SLOTMSGFLAG_MISSING)==0);
20366 default: return true;
20367 }
20368 }
20369 void clearAllSlots(int32_t type, byte flags = 0)
20370 {
20371 bound(type,0,num_types-1);
20372 switch(type)
20373 {
20374 case type_ffc:
20375 {
20376 for(int32_t q = 0; q < NUMSCRIPTFFC-1; ++q)
20377 {
20378 if(checkSkip(ffcmap[q].format, flags)) continue;
20379 ffcmap[q].scriptname = "";
20380 ffcmap[q].format = SCRIPT_FORMAT_DEFAULT;
20381 }
20382 break;
20383 }
20384 case type_global:
20385 {
20386 //Start at 1 to not clear Init
20387 for(int32_t q = 1; q < NUMSCRIPTGLOBAL; ++q)
20388 {
20389 if(checkSkip(globalmap[q].format, flags)) continue;
20390 globalmap[q].scriptname = "";
20391 globalmap[q].format = SCRIPT_FORMAT_DEFAULT;
20392 }
20393 break;
20394 }
20395 case type_itemdata:
20396 {
20397 for(int32_t q = 0; q < NUMSCRIPTITEM-1; ++q)
20398 {
20399 if(checkSkip(itemmap[q].format, flags)) continue;
20400 itemmap[q].scriptname = "";
20401 itemmap[q].format = SCRIPT_FORMAT_DEFAULT;
20402 }
20403 break;
20404 }
20405 case type_npc:
20406 {
20407 for(int32_t q = 0; q < NUMSCRIPTGUYS-1; ++q)
20408 {
20409 if(checkSkip(npcmap[q].format, flags)) continue;
20410 npcmap[q].scriptname = "";
20411 npcmap[q].format = SCRIPT_FORMAT_DEFAULT;
20412 }
20413 break;
20414 }
20415 case type_lweapon:
20416 {
20417 for(int32_t q = 0; q < NUMSCRIPTWEAPONS-1; ++q)
20418 {
20419 if(checkSkip(lwpnmap[q].format, flags)) continue;
20420 lwpnmap[q].scriptname = "";
20421 lwpnmap[q].format = SCRIPT_FORMAT_DEFAULT;
20422 }
20423 break;
20424 }
20425 case type_eweapon:
20426 {
20427 for(int32_t q = 0; q < NUMSCRIPTWEAPONS-1; ++q)
20428 {
20429 if(checkSkip(ewpnmap[q].format, flags)) continue;
20430 ewpnmap[q].scriptname = "";
20431 ewpnmap[q].format = SCRIPT_FORMAT_DEFAULT;
20432 }
20433 break;
20434 }
20435 case type_hero:
20436 {
20437 for(int32_t q = 0; q < NUMSCRIPTHERO-1; ++q)
20438 {
20439 if(checkSkip(playermap[q].format, flags)) continue;
20440 playermap[q].scriptname = "";
20441 playermap[q].format = SCRIPT_FORMAT_DEFAULT;
20442 }
20443 break;
20444 }
20445 case type_dmap:
20446 {
20447 for(int32_t q = 0; q < NUMSCRIPTSDMAP-1; ++q)
20448 {
20449 if(checkSkip(dmapmap[q].format, flags)) continue;
20450 dmapmap[q].scriptname = "";
20451 dmapmap[q].format = SCRIPT_FORMAT_DEFAULT;
20452 }
20453 break;
20454 }
20455 case type_screen:
20456 {
20457 for(int32_t q = 0; q < NUMSCRIPTSCREEN-1; ++q)
20458 {
20459 if(checkSkip(screenmap[q].format, flags)) continue;
20460 screenmap[q].scriptname = "";
20461 screenmap[q].format = SCRIPT_FORMAT_DEFAULT;
20462 }
20463 break;
20464 }
20465 case type_itemsprite:
20466 {
20467 for(int32_t q = 0; q < NUMSCRIPTSITEMSPRITE-1; ++q)
20468 {
20469 if(checkSkip(itemspritemap[q].format, flags)) continue;
20470 itemspritemap[q].scriptname = "";
20471 itemspritemap[q].format = SCRIPT_FORMAT_DEFAULT;
20472 }
20473 break;
20474 }
20475 case type_combo:
20476 {
20477 for(int32_t q = 0; q < NUMSCRIPTSCOMBODATA-1; ++q)
20478 {
20479 if(checkSkip(comboscriptmap[q].format, flags)) continue;
20480 comboscriptmap[q].scriptname = "";
20481 comboscriptmap[q].format = SCRIPT_FORMAT_DEFAULT;
20482 }
20483 break;
20484 }
20485 case type_generic:
20486 {
20487 for(int32_t q = 0; q < NUMSCRIPTSGENERIC-1; ++q)
20488 {
20489 if(checkSkip(genericmap[q].format, flags)) continue;
20490 genericmap[q].scriptname = "";
20491 genericmap[q].format = SCRIPT_FORMAT_DEFAULT;
20492 }
20493 break;
20494 }
20495 case type_subscreen:
20496 {
20497 for(int32_t q = 0; q < NUMSCRIPTSSUBSCREEN-1; ++q)
20498 {
20499 if(checkSkip(subscreenmap[q].format, flags)) continue;
20500 subscreenmap[q].scriptname = "";
20501 subscreenmap[q].format = SCRIPT_FORMAT_DEFAULT;
20502 }
20503 break;
20504 }
20505 }
20506 }
20507
20508 static bool doslots_log_output = false, doslots_comment_output = true;
20509 6 void setup_scriptslot_dlg(char* buf, byte flags)
20510 {
20511 //{ Set up the textbox at the bottom, and auto-resize height based on it
20512 6 int32_t prev_height = assignscript_dlg[14].h;
20513 6 memset(buf, 0, SLOTMSG_SIZE);
20514 //
20515 6 strcpy(buf, "Slots with matching names have been updated.\n");
20516
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(flags & SLOTMSGFLAG_MISSING)
20517 3 strcat(buf,"Scripts prefixed with '--' were not found, and will not function.\n");
20518 6 strcat(buf,"Global scripts named 'Init' will be appended to '~Init'");
20519 //
20520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 SETFLAG(assignscript_dlg[13].flags, D_SELECTED, doslots_log_output);
20521
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 SETFLAG(assignscript_dlg[51].flags, D_SELECTED, doslots_comment_output);
20522 6 assignscript_dlg[14].dp = buf;
20523 6 object_message(&assignscript_dlg[14], MSG_START, 0); //Set the width/height
20524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(int32_t diff = assignscript_dlg[14].h - prev_height) //resize dlg
20525 {
20526 6 int32_t prev_bottom = assignscript_dlg[14].y + prev_height;
20527
2/2
✓ Branch 0 taken 306 times.
✓ Branch 1 taken 6 times.
312 for(int32_t q = 1; assignscript_dlg[q].proc; ++q)
20528 {
20529
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 300 times.
306 if(q==14) continue; //Don't change self
20530
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 24 times.
300 if(assignscript_dlg[q].y < prev_bottom) continue; //above proc
20531 24 assignscript_dlg[q].y += diff;
20532 24 }
20533 6 assignscript_dlg[0].h += diff;
20534 6 jwin_center_dialog(assignscript_dlg);
20535 6 }
20536 //}
20537 6 }
20538
20539 std::string global_slotnames[NUMSCRIPTGLOBAL] = {
20540 "Init",
20541 "Active",
20542 "onExit",
20543 "onSaveLoad",
20544 "onLaunch",
20545 "onContGame",
20546 "onF6Menu",
20547 "onSave",
20548 };
20549 std::string player_slotnames[NUMSCRIPTHERO-1] = {
20550 "Init",
20551 "Active",
20552 "onDeath",
20553 "onWin",
20554 };
20555 6 byte reload_scripts(map<string, disassembled_script_data> &scripts)
20556 {
20557 6 byte slotflags = 0;
20558 char temp[100];
20559
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTFFC-1; i++)
20560 {
20561
2/2
✓ Branch 0 taken 2987 times.
✓ Branch 1 taken 79 times.
3066 if(ffcmap[i].isEmpty())
20562 2987 sprintf(temp, "Slot %d:", i+1);
20563 else
20564 {
20565 79 sprintf(temp, "Slot %d:", i+1);
20566
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 6 times.
79 if(scripts.find(ffcmap[i].scriptname) != scripts.end())
20567 73 ffcmap[i].format = SCRIPT_FORMAT_DEFAULT;
20568 else // Previously loaded script not found
20569 {
20570 6 ffcmap[i].format = SCRIPT_FORMAT_INVALID;
20571 6 slotflags |= SLOTMSGFLAG_MISSING;
20572 }
20573 }
20574 3066 ffcmap[i].slotname = temp;
20575 3066 ffcmap[i].update();
20576 3066 }
20577
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i = 0; i < NUMSCRIPTGLOBAL; i++)
20578 {
20579
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 globalmap[i].slotname=fmt::format("{}:",global_slotnames[i]);
20580
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 11 times.
48 if(!globalmap[i].isEmpty())
20581 {
20582
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 if(scripts.find(globalmap[i].scriptname) != scripts.end() || globalmap[i].scriptname == "~Init")
20583 11 globalmap[i].format = SCRIPT_FORMAT_DEFAULT;
20584 else // Unloaded
20585 {
20586 globalmap[i].format = SCRIPT_FORMAT_INVALID;
20587 slotflags |= SLOTMSGFLAG_MISSING;
20588 }
20589 11 }
20590 48 globalmap[i].update();
20591 48 }
20592
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTITEM-1; i++)
20593 {
20594
2/2
✓ Branch 0 taken 1517 times.
✓ Branch 1 taken 13 times.
1530 if(itemmap[i].isEmpty())
20595 1517 sprintf(temp, "Slot %d:", i+1);
20596 else
20597 {
20598 13 sprintf(temp, "Slot %d:", i+1);
20599
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 if(scripts.find(itemmap[i].scriptname) != scripts.end())
20600 13 itemmap[i].format = SCRIPT_FORMAT_DEFAULT;
20601 else // Previously loaded script not found
20602 {
20603 itemmap[i].format = SCRIPT_FORMAT_INVALID;
20604 slotflags |= SLOTMSGFLAG_MISSING;
20605 }
20606 }
20607 1530 itemmap[i].slotname = temp;
20608 1530 itemmap[i].update();
20609 1530 }
20610
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTGUYS-1; i++)
20611 {
20612
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(npcmap[i].isEmpty())
20613 1530 sprintf(temp, "Slot %d:", i+1);
20614 else
20615 {
20616 sprintf(temp, "Slot %d:", i+1);
20617 if(scripts.find(npcmap[i].scriptname) != scripts.end())
20618 npcmap[i].format = SCRIPT_FORMAT_DEFAULT;
20619 else // Previously loaded script not found
20620 {
20621 npcmap[i].format = SCRIPT_FORMAT_INVALID;
20622 slotflags |= SLOTMSGFLAG_MISSING;
20623 }
20624 }
20625 1530 npcmap[i].slotname = temp;
20626 1530 npcmap[i].update();
20627 1530 }
20628
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; i++)
20629 {
20630
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(ewpnmap[i].isEmpty())
20631 1530 sprintf(temp, "Slot %d:", i+1);
20632 else
20633 {
20634 sprintf(temp, "Slot %d:", i+1);
20635 if(scripts.find(ewpnmap[i].scriptname) != scripts.end())
20636 ewpnmap[i].format = SCRIPT_FORMAT_DEFAULT;
20637 else // Previously loaded script not found
20638 {
20639 ewpnmap[i].format = SCRIPT_FORMAT_INVALID;
20640 slotflags |= SLOTMSGFLAG_MISSING;
20641 }
20642 }
20643 1530 ewpnmap[i].slotname = temp;
20644 1530 ewpnmap[i].update();
20645 1530 }
20646
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; i++)
20647 {
20648
2/2
✓ Branch 0 taken 1529 times.
✓ Branch 1 taken 1 times.
1530 if(lwpnmap[i].isEmpty())
20649 1529 sprintf(temp, "Slot %d:", i+1);
20650 else
20651 {
20652 1 sprintf(temp, "Slot %d:", i+1);
20653
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(scripts.find(lwpnmap[i].scriptname) != scripts.end())
20654 1 lwpnmap[i].format = SCRIPT_FORMAT_DEFAULT;
20655 else // Previously loaded script not found
20656 {
20657 lwpnmap[i].format = SCRIPT_FORMAT_INVALID;
20658 slotflags |= SLOTMSGFLAG_MISSING;
20659 }
20660 }
20661 1530 lwpnmap[i].slotname = temp;
20662 1530 lwpnmap[i].update();
20663 1530 }
20664
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(int32_t i = 0; i < NUMSCRIPTHERO-1; i++)
20665 {
20666
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 playermap[i].slotname=fmt::format("{}:",player_slotnames[i]);
20667
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!playermap[i].isEmpty())
20668 {
20669 if(scripts.find(playermap[i].scriptname) != scripts.end())
20670 playermap[i].format = SCRIPT_FORMAT_DEFAULT;
20671 else // Unloaded
20672 {
20673 playermap[i].format = SCRIPT_FORMAT_INVALID;
20674 slotflags |= SLOTMSGFLAG_MISSING;
20675 }
20676 }
20677 24 playermap[i].update();
20678 24 }
20679
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSCREEN-1; i++)
20680 {
20681
2/2
✓ Branch 0 taken 1528 times.
✓ Branch 1 taken 2 times.
1530 if(screenmap[i].isEmpty())
20682 1528 sprintf(temp, "Slot %d:", i+1);
20683 else
20684 {
20685 2 sprintf(temp, "Slot %d:", i+1);
20686
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(scripts.find(screenmap[i].scriptname) != scripts.end())
20687 2 screenmap[i].format = SCRIPT_FORMAT_DEFAULT;
20688 else // Previously loaded script not found
20689 {
20690 screenmap[i].format = SCRIPT_FORMAT_INVALID;
20691 slotflags |= SLOTMSGFLAG_MISSING;
20692 }
20693 }
20694 1530 screenmap[i].slotname = temp;
20695 1530 screenmap[i].update();
20696 1530 }
20697
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSDMAP-1; i++)
20698 {
20699
2/2
✓ Branch 0 taken 1525 times.
✓ Branch 1 taken 5 times.
1530 if(dmapmap[i].isEmpty())
20700 1525 sprintf(temp, "Slot %d:", i+1);
20701 else
20702 {
20703 5 sprintf(temp, "Slot %d:", i+1);
20704
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(scripts.find(dmapmap[i].scriptname) != scripts.end())
20705 5 dmapmap[i].format = SCRIPT_FORMAT_DEFAULT;
20706 else // Previously loaded script not found
20707 {
20708 dmapmap[i].format = SCRIPT_FORMAT_INVALID;
20709 slotflags |= SLOTMSGFLAG_MISSING;
20710 }
20711 }
20712 1530 dmapmap[i].slotname = temp;
20713 1530 dmapmap[i].update();
20714 1530 }
20715
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE-1; i++)
20716 {
20717
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(itemspritemap[i].isEmpty())
20718 1530 sprintf(temp, "Slot %d:", i+1);
20719 else
20720 {
20721 sprintf(temp, "Slot %d:", i+1);
20722 if(scripts.find(itemspritemap[i].scriptname) != scripts.end())
20723 itemspritemap[i].format = SCRIPT_FORMAT_DEFAULT;
20724 else // Previously loaded script not found
20725 {
20726 itemspritemap[i].format = SCRIPT_FORMAT_INVALID;
20727 slotflags |= SLOTMSGFLAG_MISSING;
20728 }
20729 }
20730 1530 itemspritemap[i].slotname = temp;
20731 1530 itemspritemap[i].update();
20732 1530 }
20733
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA-1; i++)
20734 {
20735
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(comboscriptmap[i].isEmpty())
20736 3066 sprintf(temp, "Slot %d:", i+1);
20737 else
20738 {
20739 sprintf(temp, "Slot %d:", i+1);
20740 if(scripts.find(comboscriptmap[i].scriptname) != scripts.end())
20741 comboscriptmap[i].format = SCRIPT_FORMAT_DEFAULT;
20742 else // Previously loaded script not found
20743 {
20744 comboscriptmap[i].format = SCRIPT_FORMAT_INVALID;
20745 slotflags |= SLOTMSGFLAG_MISSING;
20746 }
20747 }
20748 3066 comboscriptmap[i].slotname = temp;
20749 3066 comboscriptmap[i].update();
20750 3066 }
20751
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTSGENERIC-1; i++)
20752 {
20753
2/2
✓ Branch 0 taken 3046 times.
✓ Branch 1 taken 20 times.
3066 if(genericmap[i].isEmpty())
20754 3046 sprintf(temp, "Slot %d:", i+1);
20755 else
20756 {
20757 20 sprintf(temp, "Slot %d:", i+1);
20758
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1 times.
20 if(scripts.find(genericmap[i].scriptname) != scripts.end())
20759 19 genericmap[i].format = SCRIPT_FORMAT_DEFAULT;
20760 else // Previously loaded script not found
20761 {
20762 1 genericmap[i].format = SCRIPT_FORMAT_INVALID;
20763 1 slotflags |= SLOTMSGFLAG_MISSING;
20764 }
20765 }
20766 3066 genericmap[i].slotname = temp;
20767 3066 genericmap[i].update();
20768 3066 }
20769
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSSUBSCREEN-1; i++)
20770 {
20771
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(subscreenmap[i].isEmpty())
20772 1530 sprintf(temp, "Slot %d:", i+1);
20773 else
20774 {
20775 sprintf(temp, "Slot %d:", i+1);
20776 if(scripts.find(subscreenmap[i].scriptname) != scripts.end())
20777 subscreenmap[i].format = SCRIPT_FORMAT_DEFAULT;
20778 else // Previously loaded script not found
20779 {
20780 subscreenmap[i].format = SCRIPT_FORMAT_INVALID;
20781 slotflags |= SLOTMSGFLAG_MISSING;
20782 }
20783 }
20784 1530 subscreenmap[i].slotname = temp;
20785 1530 subscreenmap[i].update();
20786 1530 }
20787 6 return slotflags;
20788 }
20789
20790 void doClearSlots(byte* flags);
20791
20792 extern byte compile_success_sample, compile_error_sample,
20793 compile_finish_sample, compile_audio_volume;
20794 static map<string, disassembled_script_data> *doslot_scripts = nullptr;
20795 21510 bool handle_slot(script_slot_data& slotdata, script_data* scriptdata)
20796 {
20797
2/2
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 21386 times.
21510 if(slotdata.hasScriptData())
20798 {
20799 124 auto& data = (*doslot_scripts)[slotdata.scriptname];
20800 124 scriptdata->meta = data.meta;
20801 124 scriptdata->pc = data.pc;
20802 124 scriptdata->end_pc = data.end_pc;
20803 124 scriptdata->zasm_script = zasm_scripts[0];
20804 124 }
20805
1/2
✓ Branch 0 taken 21386 times.
✗ Branch 1 not taken.
21386 else if(scriptdata)
20806 {
20807 21386 scriptdata->zasm_script = nullptr;
20808 21386 scriptdata->meta.zero();
20809 21386 scriptdata->pc = 0;
20810 21386 scriptdata->end_pc = 0;
20811 21386 }
20812 21510 return true;
20813 }
20814 78 bool handle_slot_map(map<int32_t, script_slot_data>& mp, int offs, script_data** scriptdata)
20815 {
20816
2/2
✓ Branch 0 taken 21510 times.
✓ Branch 1 taken 78 times.
21588 for(auto it = mp.begin(); it != mp.end(); it++)
20817 {
20818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21510 times.
21510 if(!handle_slot(it->second, scriptdata[it->first + offs]))
20819 return false;
20820 21510 }
20821 78 return true;
20822 78 }
20823
20824 void smart_slot_named(map<string, disassembled_script_data> &scripts,
20825 vector<string> const& scriptnames, map<int32_t, script_slot_data>& mp,
20826 std::string* slotnames, int slotstart, int slotend)
20827 {
20828 for(int q = slotstart; q < slotend; ++q)
20829 {
20830 auto& lval = mp[q];
20831 if(!lval.isEmpty())
20832 continue; //occupied, leave alone
20833 bool done = false;
20834 if(!done) //Check case-sensitive
20835 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
20836 {
20837 auto const& rval = scriptnames[rind];
20838 if(rval == "<none>") continue;
20839 if(rval == slotnames[q])
20840 { //Perfect match
20841 lval.updateName(rval);
20842 lval.format = scripts[lval.scriptname].format;
20843 done = true;
20844 break;
20845 }
20846 }
20847 if(!done) //Check case-insensitive
20848 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
20849 {
20850 auto const& rval = scriptnames[rind];
20851 if(rval == "<none>") continue;
20852 string lc_rv = rval, lc_slot = slotnames[q];
20853 lowerstr(lc_rv);
20854 lowerstr(lc_slot);
20855 if(lc_rv == lc_slot)
20856 { //Insensitive match
20857 lval.updateName(rval);
20858 lval.format = scripts[lval.scriptname].format;
20859 break;
20860 }
20861 }
20862 }
20863 }
20864 void smart_slot_type(map<string, disassembled_script_data> &scripts,
20865 vector<string> const& scriptnames, map<int32_t, script_slot_data>& mp,
20866 int slotcount)
20867 {
20868 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
20869 {
20870 auto const& rval = scriptnames[rind];
20871 if(rval == "<none>") continue;
20872 script_slot_data* first_open_slot = nullptr;
20873 bool done = false;
20874 for(int q = 0; q < slotcount; ++q)
20875 {
20876 auto& lval = mp[q];
20877 if(lval.isEmpty())
20878 {
20879 if(!first_open_slot)
20880 first_open_slot = &lval;
20881 }
20882 else if(lval.scriptname == rval)
20883 {
20884 done = true;
20885 break;
20886 }
20887 }
20888 if(!done)
20889 {
20890 if(!first_open_slot)
20891 break; //no slots left to assign to!
20892 first_open_slot->updateName(rval);
20893 first_open_slot->format = scripts[first_open_slot->scriptname].format;
20894 }
20895 }
20896 }
20897
20898 6 bool do_slots(vector<shared_ptr<ZScript::Opcode>> const& zasm,
20899 map<string, disassembled_script_data> &scripts, int assign_mode)
20900 {
20901 6 large_dialog(assignscript_dlg);
20902 6 int32_t ret = 3;
20903 6 char slots_msg[SLOTMSG_SIZE] = {0};
20904 6 byte slotflags = reload_scripts(scripts);
20905 6 setup_scriptslot_dlg(slots_msg, slotflags);
20906 6 bool retval = false;
20907
20908 6 popup_zqdialog_start();
20909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 while(!assign_mode)
20910 {
20911 slotflags = reload_scripts(scripts);
20912 ret = do_zqdialog(assignscript_dlg, ret);
20913
20914 switch(ret)
20915 {
20916 case 0:
20917 case 2:
20918 //Cancel
20919 goto exit_do_slots;
20920
20921 case 3: goto auto_do_slots;
20922
20923 case 6:
20924 //<<, FFC
20925 {
20926 int32_t lind = assignscript_dlg[4].d1;
20927 int32_t rind = assignscript_dlg[5].d1;
20928
20929 if(lind < 0 || rind < 0)
20930 break;
20931
20932 if(asffcscripts[rind] == "<none>")
20933 {
20934 ffcmap[lind].scriptname = "";
20935 ffcmap[lind].format = SCRIPT_FORMAT_DEFAULT;
20936 }
20937 else
20938 {
20939 ffcmap[lind].updateName(asffcscripts[rind]);
20940 ffcmap[lind].format = scripts[ffcmap[lind].scriptname].format;
20941 }
20942
20943 break;
20944 }
20945 case 9:
20946 //<<, Global
20947 {
20948 int32_t lind = assignscript_dlg[7].d1;
20949 int32_t rind = assignscript_dlg[8].d1;
20950
20951 if(lind < 0 || rind < 0)
20952 break;
20953
20954 if(lind == 0)
20955 {
20956 jwin_alert("Error","ZScript reserves this slot.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
20957 break;
20958 }
20959
20960 if(asglobalscripts[rind] == "<none>")
20961 {
20962 globalmap[lind].scriptname = "";
20963 globalmap[lind].format = SCRIPT_FORMAT_DEFAULT;
20964 }
20965 else
20966 {
20967 globalmap[lind].updateName(asglobalscripts[rind]);
20968 globalmap[lind].format = scripts[globalmap[lind].scriptname].format;
20969 }
20970
20971 break;
20972 }
20973 case 12:
20974 //<<, ITEM
20975 {
20976 int32_t lind = assignscript_dlg[10].d1;
20977 int32_t rind = assignscript_dlg[11].d1;
20978
20979 if(lind < 0 || rind < 0)
20980 break;
20981
20982 if(asitemscripts[rind] == "<none>")
20983 {
20984 itemmap[lind].scriptname = "";
20985 itemmap[lind].format = SCRIPT_FORMAT_DEFAULT;
20986 }
20987 else
20988 {
20989 itemmap[lind].updateName(asitemscripts[rind]);
20990 itemmap[lind].format = scripts[itemmap[lind].scriptname].format;
20991 }
20992
20993 break;
20994 }
20995 case 20:
20996 //<<, NPC
20997 {
20998 int32_t lind = assignscript_dlg[18].d1;
20999 int32_t rind = assignscript_dlg[19].d1;
21000
21001 if(lind < 0 || rind < 0)
21002 break;
21003
21004 if(asnpcscripts[rind] == "<none>")
21005 {
21006 npcmap[lind].scriptname = "";
21007 npcmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21008 }
21009 else
21010 {
21011 npcmap[lind].updateName(asnpcscripts[rind]);
21012 npcmap[lind].format = scripts[npcmap[lind].scriptname].format;
21013 }
21014
21015 break;
21016 }
21017 case 23:
21018 //<<, LWeapon
21019 {
21020 int32_t lind = assignscript_dlg[21].d1;
21021 int32_t rind = assignscript_dlg[22].d1;
21022
21023 if(lind < 0 || rind < 0)
21024 break;
21025
21026 if(aslweaponscripts[rind] == "<none>")
21027 {
21028 lwpnmap[lind].scriptname = "";
21029 lwpnmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21030 }
21031 else
21032 {
21033 lwpnmap[lind].updateName(aslweaponscripts[rind]);
21034 lwpnmap[lind].format = scripts[lwpnmap[lind].scriptname].format;
21035 }
21036
21037 break;
21038 }
21039 case 26:
21040 //<<, EWeapon
21041 {
21042 int32_t lind = assignscript_dlg[24].d1;
21043 int32_t rind = assignscript_dlg[25].d1;
21044
21045 if(lind < 0 || rind < 0)
21046 break;
21047
21048 if(aseweaponscripts[rind] == "<none>")
21049 {
21050 ewpnmap[lind].scriptname = "";
21051 ewpnmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21052 }
21053 else
21054 {
21055 ewpnmap[lind].updateName(aseweaponscripts[rind]);
21056 ewpnmap[lind].format = scripts[ewpnmap[lind].scriptname].format;
21057 }
21058
21059 break;
21060 }
21061 case 29:
21062 //<<, Hero
21063 {
21064 int32_t lind = assignscript_dlg[27].d1;
21065 int32_t rind = assignscript_dlg[28].d1;
21066
21067 if(lind < 0 || rind < 0)
21068 break;
21069
21070 if(asplayerscripts[rind] == "<none>")
21071 {
21072 playermap[lind].scriptname = "";
21073 playermap[lind].format = SCRIPT_FORMAT_DEFAULT;
21074 }
21075 else
21076 {
21077 playermap[lind].updateName(asplayerscripts[rind]);
21078 playermap[lind].format = scripts[playermap[lind].scriptname].format;
21079 }
21080
21081 break;
21082 }
21083 case 32:
21084 //<<, Screendata
21085 {
21086 int32_t lind = assignscript_dlg[30].d1;
21087 int32_t rind = assignscript_dlg[31].d1;
21088
21089 if(lind < 0 || rind < 0)
21090 break;
21091
21092 if(asscreenscripts[rind] == "<none>")
21093 {
21094 screenmap[lind].scriptname = "";
21095 screenmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21096 }
21097 else
21098 {
21099 screenmap[lind].updateName(asscreenscripts[rind]);
21100 screenmap[lind].format = scripts[screenmap[lind].scriptname].format;
21101 }
21102
21103 break;
21104 }
21105 case 35:
21106 //<<, dmapdata
21107 {
21108 int32_t lind = assignscript_dlg[33].d1;
21109 int32_t rind = assignscript_dlg[34].d1;
21110
21111 if(lind < 0 || rind < 0)
21112 break;
21113
21114 if(asdmapscripts[rind] == "<none>")
21115 {
21116 dmapmap[lind].scriptname = "";
21117 dmapmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21118 }
21119 else
21120 {
21121 dmapmap[lind].updateName(asdmapscripts[rind]);
21122 dmapmap[lind].format = scripts[dmapmap[lind].scriptname].format;
21123 }
21124
21125 break;
21126 }
21127 case 38:
21128 //<<, itemsprite
21129 {
21130 int32_t lind = assignscript_dlg[36].d1;
21131 int32_t rind = assignscript_dlg[37].d1;
21132
21133 if(lind < 0 || rind < 0)
21134 break;
21135
21136 if(asitemspritescripts[rind] == "<none>")
21137 {
21138 itemspritemap[lind].scriptname = "";
21139 itemspritemap[lind].format = SCRIPT_FORMAT_DEFAULT;
21140 }
21141 else
21142 {
21143 itemspritemap[lind].updateName(asitemspritescripts[rind]);
21144 itemspritemap[lind].format = scripts[itemspritemap[lind].scriptname].format;
21145 }
21146
21147 break;
21148 }
21149 case 41:
21150 //<<, comboscript
21151 {
21152 int32_t lind = assignscript_dlg[39].d1;
21153 int32_t rind = assignscript_dlg[40].d1;
21154
21155 if(lind < 0 || rind < 0)
21156 break;
21157
21158 if(ascomboscripts[rind] == "<none>")
21159 {
21160 comboscriptmap[lind].scriptname = "";
21161 comboscriptmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21162 }
21163 else
21164 {
21165 comboscriptmap[lind].updateName(ascomboscripts[rind]);
21166 comboscriptmap[lind].format = scripts[comboscriptmap[lind].scriptname].format;
21167 }
21168
21169 break;
21170 }
21171 case 47:
21172 //<<, generic script
21173 {
21174 int32_t lind = assignscript_dlg[45].d1;
21175 int32_t rind = assignscript_dlg[46].d1;
21176
21177 if(lind < 0 || rind < 0)
21178 break;
21179
21180 if(asgenericscripts[rind] == "<none>")
21181 {
21182 genericmap[lind].scriptname = "";
21183 genericmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21184 }
21185 else
21186 {
21187 genericmap[lind].updateName(asgenericscripts[rind]);
21188 genericmap[lind].format = scripts[genericmap[lind].scriptname].format;
21189 }
21190
21191 break;
21192 }
21193 case 50:
21194 //<<, subscreen script
21195 {
21196 int32_t lind = assignscript_dlg[48].d1;
21197 int32_t rind = assignscript_dlg[49].d1;
21198
21199 if(lind < 0 || rind < 0)
21200 break;
21201
21202 if(assubscreenscripts[rind] == "<none>")
21203 {
21204 subscreenmap[lind].scriptname = "";
21205 subscreenmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21206 }
21207 else
21208 {
21209 subscreenmap[lind].updateName(assubscreenscripts[rind]);
21210 subscreenmap[lind].format = scripts[subscreenmap[lind].scriptname].format;
21211 }
21212
21213 break;
21214 }
21215
21216 case 42:
21217 //Script Info, information
21218 {
21219 disassembled_script_data* target = nullptr;
21220 switch(get_selected_tab((TABPANEL*)assignscript_dlg[1].dp))
21221 {
21222 default:
21223 case 0: //FFC
21224 {
21225 int32_t id = assignscript_dlg[4].d1;
21226 if(id > -1 && ffcmap[id].hasScriptData())
21227 {
21228 target = &(scripts[ffcmap[id].scriptname]);
21229 }
21230 break;
21231 }
21232 case 1: //Global
21233 {
21234 int32_t id = assignscript_dlg[7].d1;
21235 if(id > -1 && globalmap[id].hasScriptData())
21236 {
21237 target = &(scripts[globalmap[id].scriptname]);
21238 }
21239 break;
21240 }
21241 case 2: //Item
21242 {
21243 int32_t id = assignscript_dlg[10].d1;
21244 if(id > -1 && itemmap[id].hasScriptData())
21245 {
21246 target = &(scripts[itemmap[id].scriptname]);
21247 }
21248 break;
21249 }
21250 case 3: //npc
21251 {
21252 int32_t id = assignscript_dlg[19].d1;
21253 if(id > -1 && npcmap[id].hasScriptData())
21254 {
21255 target = &(scripts[npcmap[id].scriptname]);
21256 }
21257 break;
21258 }
21259 case 4: //lweapon
21260 {
21261 int32_t id = assignscript_dlg[21].d1;
21262 if(id > -1 && lwpnmap[id].hasScriptData())
21263 {
21264 target = &(scripts[lwpnmap[id].scriptname]);
21265 }
21266 break;
21267 }
21268 case 5: //eweapon
21269 {
21270 int32_t id = assignscript_dlg[24].d1;
21271 if(id > -1 && ewpnmap[id].hasScriptData())
21272 {
21273 target = &(scripts[ewpnmap[id].scriptname]);
21274 }
21275 break;
21276 }
21277 case 6: //hero
21278 {
21279 int32_t id = assignscript_dlg[27].d1;
21280 if(id > -1 && playermap[id].hasScriptData())
21281 {
21282 target = &(scripts[playermap[id].scriptname]);
21283 }
21284 break;
21285 }
21286 case 7: //dmap
21287 {
21288 int32_t id = assignscript_dlg[33].d1;
21289 if(id > -1 && dmapmap[id].hasScriptData())
21290 {
21291 target = &(scripts[dmapmap[id].scriptname]);
21292 }
21293 break;
21294 }
21295 case 8: //screen
21296 {
21297 int32_t id = assignscript_dlg[30].d1;
21298 if(id > -1 && screenmap[id].hasScriptData())
21299 {
21300 target = &(scripts[screenmap[id].scriptname]);
21301 }
21302 break;
21303 }
21304 case 9: //itemsprite
21305 {
21306 int32_t id = assignscript_dlg[36].d1;
21307 if(id > -1 && itemspritemap[id].hasScriptData())
21308 {
21309 target = &(scripts[itemspritemap[id].scriptname]);
21310 }
21311 break;
21312 }
21313 case 10: //combo
21314 {
21315 int32_t id = assignscript_dlg[39].d1;
21316 if(id > -1 && comboscriptmap[id].hasScriptData())
21317 {
21318 target = &(scripts[comboscriptmap[id].scriptname]);
21319 }
21320 break;
21321 }
21322 case 11: //Generic
21323 {
21324 int32_t id = assignscript_dlg[45].d1;
21325 if(id > -1 && genericmap[id].hasScriptData())
21326 {
21327 target = &(scripts[genericmap[id].scriptname]);
21328 }
21329 break;
21330 }
21331 case 12: //Subscreen
21332 {
21333 int32_t id = assignscript_dlg[48].d1;
21334 if(id > -1 && subscreenmap[id].hasScriptData())
21335 {
21336 target = &(scripts[subscreenmap[id].scriptname]);
21337 }
21338 break;
21339 }
21340 }
21341 if(target)
21342 showScriptInfo(&target->meta);
21343 break;
21344 }
21345
21346 case 43:
21347 //Script Info, information
21348 {
21349 disassembled_script_data* target = NULL;
21350 switch(get_selected_tab((TABPANEL*)assignscript_dlg[1].dp))
21351 {
21352 default:
21353 case 0: //FFC
21354 {
21355 int32_t id = assignscript_dlg[5].d1;
21356 if(id < 0 || asffcscripts[id] == "<none>" || asffcscripts[id].at(0) == '-') break;
21357 target = &(scripts[asffcscripts[id]]);
21358 break;
21359 }
21360 case 1: //Global
21361 {
21362 int32_t id = assignscript_dlg[8].d1;
21363 if(id < 0 || asglobalscripts[id] == "<none>" || asglobalscripts[id].at(0) == '-') break;
21364 target = &(scripts[asglobalscripts[id]]);
21365 break;
21366 }
21367 case 2: //Item
21368 {
21369 int32_t id = assignscript_dlg[11].d1;
21370 if(id < 0 || asitemscripts[id] == "<none>" || asitemscripts[id].at(0) == '-') break;
21371 target = &(scripts[asitemscripts[id]]);
21372 break;
21373 }
21374 case 3: //npc
21375 {
21376 int32_t id = assignscript_dlg[20].d1;
21377 if(id < 0 || asnpcscripts[id] == "<none>" || asnpcscripts[id].at(0) == '-') break;
21378 target = &(scripts[asnpcscripts[id]]);
21379 break;
21380 }
21381 case 4: //lweapon
21382 {
21383 int32_t id = assignscript_dlg[22].d1;
21384 if(id < 0 || aslweaponscripts[id] == "<none>" || aslweaponscripts[id].at(0) == '-') break;
21385 target = &(scripts[aslweaponscripts[id]]);
21386 break;
21387 }
21388 case 5: //eweapon
21389 {
21390 int32_t id = assignscript_dlg[25].d1;
21391 if(id < 0 || aseweaponscripts[id] == "<none>" || aseweaponscripts[id].at(0) == '-') break;
21392 target = &(scripts[aseweaponscripts[id]]);
21393 break;
21394 }
21395 case 6: //hero
21396 {
21397 int32_t id = assignscript_dlg[28].d1;
21398 if(id < 0 || asplayerscripts[id] == "<none>" || asplayerscripts[id].at(0) == '-') break;
21399 target = &(scripts[asplayerscripts[id]]);
21400 break;
21401 }
21402 case 7: //dmap
21403 {
21404 int32_t id = assignscript_dlg[34].d1;
21405 if(id < 0 || asdmapscripts[id] == "<none>" || asdmapscripts[id].at(0) == '-') break;
21406 target = &(scripts[asdmapscripts[id]]);
21407 break;
21408 }
21409 case 8: //screen
21410 {
21411 int32_t id = assignscript_dlg[31].d1;
21412 if(id < 0 || asscreenscripts[id] == "<none>" || asscreenscripts[id].at(0) == '-') break;
21413 target = &(scripts[asscreenscripts[id]]);
21414 break;
21415 }
21416 case 9: //itemsprite
21417 {
21418 int32_t id = assignscript_dlg[37].d1;
21419 if(id < 0 || asitemspritescripts[id] == "<none>" || asitemspritescripts[id].at(0) == '-') break;
21420 target = &(scripts[asitemspritescripts[id]]);
21421 break;
21422 }
21423 case 10: //combo
21424 {
21425 int32_t id = assignscript_dlg[40].d1;
21426 if(id < 0 || ascomboscripts[id] == "<none>" || ascomboscripts[id].at(0) == '-') break;
21427 target = &(scripts[ascomboscripts[id]]);
21428 break;
21429 }
21430 case 11: //generic
21431 {
21432 int32_t id = assignscript_dlg[46].d1;
21433 if(id < 0 || asgenericscripts[id] == "<none>" || asgenericscripts[id].at(0) == '-') break;
21434 target = &(scripts[asgenericscripts[id]]);
21435 break;
21436 }
21437 case 12: //subscreen
21438 {
21439 int32_t id = assignscript_dlg[49].d1;
21440 if(id < 0 || assubscreenscripts[id] == "<none>" || assubscreenscripts[id].at(0) == '-') break;
21441 target = &(scripts[assubscreenscripts[id]]);
21442 break;
21443 }
21444 }
21445 if(target)
21446 showScriptInfo(&target->meta);
21447 break;
21448 }
21449
21450 case 44:
21451 //Clear, clear slots of current type- after a confirmation.
21452 {
21453 doClearSlots(&slotflags);
21454 break;
21455 }
21456 }
21457 }
21458
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(assign_mode == 2) //Smart Assign
21459 {
21460 //For global/hero scripts, match slot names if unoccupied
21461 smart_slot_named(scripts, asglobalscripts, globalmap, global_slotnames, 1, NUMSCRIPTGLOBAL);
21462 smart_slot_named(scripts, asplayerscripts, playermap, player_slotnames, 0, NUMSCRIPTHERO-1);
21463 //For other scripts, assign all un-assigned scripts
21464 smart_slot_type(scripts, asffcscripts, ffcmap, NUMSCRIPTFFC-1);
21465 smart_slot_type(scripts, asitemscripts, itemmap, NUMSCRIPTITEM-1);
21466 smart_slot_type(scripts, asnpcscripts, npcmap, NUMSCRIPTGUYS-1);
21467 smart_slot_type(scripts, aslweaponscripts, lwpnmap, NUMSCRIPTWEAPONS-1);
21468 smart_slot_type(scripts, aseweaponscripts, ewpnmap, NUMSCRIPTWEAPONS-1);
21469 smart_slot_type(scripts, asscreenscripts, screenmap, NUMSCRIPTSCREEN-1);
21470 smart_slot_type(scripts, asdmapscripts, dmapmap, NUMSCRIPTSDMAP-1);
21471 smart_slot_type(scripts, asitemspritescripts, itemspritemap, NUMSCRIPTSITEMSPRITE-1);
21472 smart_slot_type(scripts, ascomboscripts, comboscriptmap, NUMSCRIPTSCOMBODATA-1);
21473 smart_slot_type(scripts, asgenericscripts, genericmap, NUMSCRIPTSGENERIC-1);
21474 smart_slot_type(scripts, assubscreenscripts, subscreenmap, NUMSCRIPTSSUBSCREEN-1);
21475 }
21476 auto_do_slots:
21477 6 doslots_log_output = (assignscript_dlg[13].flags == D_SELECTED);
21478 6 doslots_comment_output = (assignscript_dlg[51].flags == D_SELECTED);
21479 6 doslot_scripts = &scripts;
21480 //OK
21481 {
21482
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(doslots_log_output)
21483 {
21484 string outstr;
21485 write_script(zasm, outstr, doslots_comment_output, doslot_scripts);
21486 safe_al_trace(outstr);
21487 }
21488 6 auto start_assign_time = std::chrono::steady_clock::now();
21489 6 string zasm_str;
21490
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 write_script(zasm, zasm_str, false, nullptr);
21491
21492 6 std::vector<ffscript> zasm;
21493
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(parse_script_string(zasm, zasm_str, false))
21494 goto exit_do_slots;
21495
21496 6 zasm_scripts.clear();
21497
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 zasm_scripts.emplace_back(std::make_shared<zasm_script>(std::move(zasm)));
21498
21499
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(ffcmap, 1, ffscripts))
21500 goto exit_do_slots;
21501
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(globalmap, 0, globalscripts))
21502 goto exit_do_slots;
21503
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(itemmap, 1, itemscripts))
21504 goto exit_do_slots;
21505
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(npcmap, 1, guyscripts))
21506 goto exit_do_slots;
21507
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(lwpnmap, 1, lwpnscripts))
21508 goto exit_do_slots;
21509
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(ewpnmap, 1, ewpnscripts))
21510 goto exit_do_slots;
21511
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(playermap, 1, playerscripts))
21512 goto exit_do_slots;
21513
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(dmapmap, 1, dmapscripts))
21514 goto exit_do_slots;
21515
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(screenmap, 1, screenscripts))
21516 goto exit_do_slots;
21517
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(itemspritemap, 1, itemspritescripts))
21518 goto exit_do_slots;
21519
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(comboscriptmap, 1, comboscripts))
21520 goto exit_do_slots;
21521
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(genericmap, 1, genericscripts))
21522 goto exit_do_slots;
21523
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(subscreenmap, 1, subscreenscripts))
21524 goto exit_do_slots;
21525
21526 6 auto end_assign_time = std::chrono::steady_clock::now();
21527
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 int compile_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end_assign_time - start_assign_time).count();
21528
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 al_trace("Assign Slots took %d ms\n", compile_time_ms);
21529 6 char buf[256] = {0};
21530 12 sprintf(buf, "ZScripts successfully loaded into script slots"
21531 6 "\nAssign Slots took %d ms", compile_time_ms);
21532
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 compile_finish_sample = vbound(zc_get_config("Compiler","compile_finish_sample",20),0,255);
21533
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 compile_audio_volume = vbound(zc_get_config("Compiler","compile_audio_volume",200),0,255);
21534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if ( compile_finish_sample > 0 )
21535 {
21536
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(sfxdat)
21537 sfx_voice[compile_finish_sample]=allocate_voice((SAMPLE*)sfxdata[compile_finish_sample].dat);
21538
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 else sfx_voice[compile_finish_sample]=allocate_voice(&customsfxdata[compile_finish_sample]);
21539
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 voice_set_volume(sfx_voice[compile_finish_sample], compile_audio_volume);
21540
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 voice_start(sfx_voice[compile_finish_sample]);
21541 6 }
21542
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!assign_mode)
21543 InfoDialog("Slots Assigned",buf).show();
21544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if ( compile_finish_sample > 0 )
21545 {
21546
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(sfx_voice[compile_finish_sample]!=-1)
21547 {
21548
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 deallocate_voice(sfx_voice[compile_finish_sample]);
21549 6 sfx_voice[compile_finish_sample]=-1;
21550 6 }
21551 6 }
21552
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 build_biffs_list();
21553
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 build_biitems_list();
21554 6 retval = true;
21555 6 goto exit_do_slots;
21556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 }
21557 exit_do_slots:
21558 6 doslot_scripts = nullptr;
21559 6 popup_zqdialog_end();
21560 6 return retval;
21561 }
21562
21563 static char slottype_str_buf[32];
21564
21565 const char *slottype_list(int32_t index, int32_t *list_size)
21566 {
21567 if(index >= 0)
21568 {
21569 bound(index,0,num_types-1);
21570
21571 switch(index)
21572 {
21573 case type_ffc:
21574 strcpy(slottype_str_buf, "FFC");
21575 break;
21576 case type_global:
21577 strcpy(slottype_str_buf, "Global");
21578 break;
21579 case type_itemdata:
21580 strcpy(slottype_str_buf, "Item");
21581 break;
21582 case type_npc:
21583 strcpy(slottype_str_buf, "NPC");
21584 break;
21585 case type_lweapon:
21586 strcpy(slottype_str_buf, "LWeapon");
21587 break;
21588 case type_eweapon:
21589 strcpy(slottype_str_buf, "EWeapon");
21590 break;
21591 case type_hero:
21592 strcpy(slottype_str_buf, "Hero");
21593 break;
21594 case type_dmap:
21595 strcpy(slottype_str_buf, "DMap");
21596 break;
21597 case type_screen:
21598 strcpy(slottype_str_buf, "Screen");
21599 break;
21600 case type_itemsprite:
21601 strcpy(slottype_str_buf, "ItemSprite");
21602 break;
21603 case type_combo:
21604 strcpy(slottype_str_buf, "Combo");
21605 break;
21606 case type_generic:
21607 strcpy(slottype_str_buf, "Generic");
21608 break;
21609 case type_subscreen:
21610 strcpy(slottype_str_buf, "Subscreen");
21611 break;
21612 }
21613
21614 return slottype_str_buf;
21615 }
21616 *list_size = 11;
21617 return NULL;
21618 }
21619 12 static ListData slottype_sel_list(slottype_list, &font);
21620
21621 static DIALOG clearslots_dlg[] =
21622 {
21623 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Clear Slots", NULL, NULL },
21624 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
21625 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
21626 12 { jwin_droplist_proc, 50, 28+16, 70, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
21627 12 { jwin_radio_proc, 40, 34+00, 81, 9, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Clear Script Type:", NULL, NULL },
21628 12 { jwin_radio_proc, 40, 34+32, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear Missing (--) Slots", NULL, NULL },
21629 12 { jwin_radio_proc, 40, 34+80, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear All", NULL, NULL },
21630 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
21631 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
21632 };
21633
21634 void doClearSlots(byte* flags)
21635 {
21636 //{ Setup
21637 clearslots_dlg[0].dp2=get_zc_font(font_lfont);
21638 clearslots_dlg[3].d1 = get_selected_tab((TABPANEL*)assignscript_dlg[1].dp); //Default to current tab's type
21639 clearslots_dlg[4].flags |= D_SELECTED;
21640 clearslots_dlg[5].flags &= ~D_SELECTED;
21641 clearslots_dlg[6].flags &= ~D_SELECTED;
21642 if(((*flags) & SLOTMSGFLAG_MISSING) == 0)
21643 clearslots_dlg[5].flags |= D_DISABLED;
21644 else
21645 clearslots_dlg[5].flags &= ~D_DISABLED;
21646 //}
21647
21648 large_dialog(clearslots_dlg);
21649
21650 if(do_zqdialog(clearslots_dlg,2)==1)
21651 {
21652 int32_t q = 3;
21653 while((clearslots_dlg[++q].flags & D_SELECTED) == 0);
21654 switch(q)
21655 {
21656 case 4: //Clear type
21657 {
21658 clearAllSlots(clearslots_dlg[3].d1);
21659 break;
21660 }
21661 case 5: //Clear Missing
21662 {
21663 for(int32_t q = 0; q <= 10; ++q)
21664 clearAllSlots(q,SLOTMSGFLAG_MISSING);
21665 break;
21666 }
21667 case 6: //Clear ALL
21668 {
21669 for(int32_t q = 0; q <= 10; ++q)
21670 clearAllSlots(q);
21671 break;
21672 }
21673 }
21674 }
21675 }
21676
21677 static DIALOG exportzasm_dlg[] =
21678 {
21679 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Export ZASM", NULL, NULL },
21680 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
21681 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
21682 12 { jwin_droplist_proc, 50, 28+16, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
21683 12 { jwin_droplist_proc, 50, 28+48, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
21684 12 { jwin_text_proc, 50, 28+8, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Type:", NULL, NULL },
21685 12 { jwin_text_proc, 50, 28+40, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Slot:", NULL, NULL },
21686 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
21687 };
21688
21689 static DIALOG importzasm_dlg[] =
21690 {
21691 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Import ZASM", NULL, NULL },
21692 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
21693 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
21694 12 { jwin_droplist_proc, 50, 28+16, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
21695 12 { jwin_droplist_proc, 50, 28+48, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
21696 // 5
21697 12 { jwin_text_proc, 50, 28+8, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Type:", NULL, NULL },
21698 12 { jwin_text_proc, 50, 28+40, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Slot:", NULL, NULL },
21699 12 { jwin_text_proc, 50, 28+72, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Name:", NULL, NULL },
21700 12 { jwin_edit_proc, 50, 28+80, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 19, 0, NULL, NULL, NULL },
21701
21702 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
21703 };
21704 extern ListData itemscript_list;
21705 extern ListData itemspritescript_list;
21706 extern ListData lweaponscript_list;
21707 extern ListData npcscript_list;
21708 extern ListData eweaponscript_list;
21709 extern ListData comboscript_list;
21710
21711 8 void center_zscript_dialogs()
21712 {
21713 8 jwin_center_dialog(exportzasm_dlg);
21714 8 jwin_center_dialog(importzasm_dlg);
21715 8 jwin_center_dialog(clearslots_dlg);
21716 8 }
21717
21718 // array of voices, one for each sfx sample in the data file
21719 // 0+ = voice #
21720 // -1 = voice not allocated
21721 int32_t sfx_voice[WAV_COUNT];
21722
21723 void Z_init_sound()
21724 {
21725 for(int32_t i=0; i<WAV_COUNT; i++)
21726 sfx_voice[i]=-1;
21727
21728 // master_volume(digi_volume,midi_volume);
21729 }
21730
21731 // returns number of voices currently allocated
21732 int32_t sfx_count()
21733 {
21734 int32_t c=0;
21735
21736 for(int32_t i=0; i<WAV_COUNT; i++)
21737 if(sfx_voice[i]!=-1)
21738 ++c;
21739
21740 return c;
21741 }
21742
21743 // clean up finished samples
21744 void sfx_cleanup()
21745 {
21746 for(int32_t i=0; i<WAV_COUNT; i++)
21747 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
21748 {
21749 deallocate_voice(sfx_voice[i]);
21750 sfx_voice[i]=-1;
21751 }
21752 }
21753
21754 // allocates a voice for the sample "wav_index" (index into zelda.dat)
21755 // if a voice is already allocated (and/or playing), then it just returns true
21756 // Returns true: voice is allocated
21757 // false: unsuccessful
21758 SAMPLE templist[WAV_COUNT];
21759
21760 bool sfx_init(int32_t index)
21761 {
21762 // check index
21763 if(index<1 || index>=WAV_COUNT)
21764 return false;
21765
21766 if(sfx_voice[index]==-1)
21767 {
21768 sfx_voice[index]=allocate_voice(&templist[index]);
21769 }
21770
21771 return sfx_voice[index] != -1;
21772 }
21773
21774 // plays an sfx sample
21775 void sfx(int32_t index,int32_t pan,bool loop,bool restart,int32_t vol,int32_t freq)
21776 {
21777 if(!sfx_init(index))
21778 return;
21779
21780 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
21781 voice_set_pan(sfx_voice[index],pan);
21782
21783 int32_t pos = voice_get_position(sfx_voice[index]);
21784
21785 if(restart) voice_set_position(sfx_voice[index],0);
21786
21787 if(pos<=0)
21788 voice_start(sfx_voice[index]);
21789 }
21790
21791 // start it (in loop mode) if it's not already playing,
21792 // otherwise just leave it in its current position
21793 void cont_sfx(int32_t index)
21794 {
21795 if(!sfx_init(index))
21796 return;
21797
21798 if(voice_get_position(sfx_voice[index])<=0)
21799 {
21800 voice_set_position(sfx_voice[index],0);
21801 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
21802 voice_start(sfx_voice[index]);
21803 }
21804 }
21805
21806 // adjust parameters while playing
21807 void adjust_sfx(int32_t index,int32_t pan,bool loop)
21808 {
21809 if(index<0 || index>=WAV_COUNT || sfx_voice[index]==-1)
21810 return;
21811
21812 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
21813 voice_set_pan(sfx_voice[index],pan);
21814 }
21815
21816 // pauses a voice
21817 void pause_sfx(int32_t index)
21818 {
21819 if(index>=0 && index<WAV_COUNT && sfx_voice[index]!=-1)
21820 voice_stop(sfx_voice[index]);
21821 }
21822
21823 // resumes a voice
21824 void resume_sfx(int32_t index)
21825 {
21826 if(index>=0 && index<WAV_COUNT && sfx_voice[index]!=-1)
21827 voice_start(sfx_voice[index]);
21828 }
21829
21830 // pauses all active voices
21831 void pause_all_sfx()
21832 {
21833 for(int32_t i=0; i<WAV_COUNT; i++)
21834 if(sfx_voice[i]!=-1)
21835 voice_stop(sfx_voice[i]);
21836 }
21837
21838 // resumes all paused voices
21839 void resume_all_sfx()
21840 {
21841 for(int32_t i=0; i<WAV_COUNT; i++)
21842 if(sfx_voice[i]!=-1)
21843 voice_start(sfx_voice[i]);
21844 }
21845
21846 // stops an sfx and deallocates the voice
21847 void stop_sfx(int32_t index)
21848 {
21849 if(index<0 || index>=WAV_COUNT)
21850 return;
21851
21852 if(sfx_voice[index]!=-1)
21853 {
21854 deallocate_voice(sfx_voice[index]);
21855 sfx_voice[index]=-1;
21856 }
21857 }
21858
21859 void kill_sfx()
21860 {
21861 for(int32_t i=0; i<WAV_COUNT; i++)
21862 if(sfx_voice[i]!=-1)
21863 {
21864 deallocate_voice(sfx_voice[i]);
21865 sfx_voice[i]=-1;
21866 }
21867 }
21868
21869 int32_t pan(int32_t x)
21870 {
21871 return 128;
21872 /*switch(pan_style)
21873 {
21874 case 0: return 128;
21875 case 1: return vbound((x>>1)+68,0,255);
21876 case 2: return vbound(((x*3)>>2)+36,0,255);
21877 }
21878 return vbound(x,0,255);*/
21879 }
21880
21881
21882 void change_sfx(SAMPLE *sfx1, SAMPLE *sfx2)
21883 {
21884 sfx1->bits = sfx2->bits;
21885 sfx1->stereo = sfx2->stereo;
21886 sfx1->freq = sfx2->freq;
21887 sfx1->priority = sfx2->priority;
21888 sfx1->len = sfx2->len;
21889 sfx1->loop_start = sfx2->loop_start;
21890 sfx1->loop_end = sfx2->loop_end;
21891 sfx1->param = sfx2->param;
21892
21893 if(sfx1->data != NULL)
21894 {
21895 free(sfx1->data);
21896 }
21897
21898 if(sfx2->data == NULL)
21899 sfx1->data = NULL;
21900 else
21901 {
21902 // When quests are saved and loaded, data is written in words.
21903 // If the last byte is dropped, it'll cause the sound to end with
21904 // a click. It could simply be extended and padded with 0, but
21905 // that causes compatibility issues... So we'll cut off
21906 // the last byte and decrease the length.
21907
21908 int32_t len = (sfx1->bits==8?1:2)*(sfx1->stereo == 0 ? 1 : 2)*sfx1->len;
21909
21910 while(len%sizeof(word))
21911 {
21912 // sizeof(word) should be 2, so this doesn't really need
21913 // to be a loop, but what the heck.
21914 sfx1->len--;
21915 len = (sfx1->bits==8?1:2)*(sfx1->stereo == 0 ? 1 : 2)*sfx1->len;
21916 }
21917
21918 sfx1->data = malloc(len);
21919 memcpy(sfx1->data, sfx2->data, len);
21920 }
21921 }
21922
21923 bool confirmBox(const char *m1, const char *m2, const char *m3)
21924 {
21925 if(!m3)
21926 {
21927 if(!m2) m2 = "Are you sure?";
21928 else m3 = "Are you sure?";
21929 }
21930 return jwin_alert("Confirmation", m1, m2, m3, "Yes", "No", 'y', 'n', get_zc_font(font_lfont)) == 1;
21931 }
21932
21933 int32_t onSelectSFX()
21934 {
21935 SFXListerDialog(0).show();
21936 refresh(rMAP+rCOMBOS);
21937 return D_O_K;
21938 }
21939
21940 bool saveWAV(int32_t slot, const char *filename)
21941 {
21942 if (slot < 1 || slot >= 511 )
21943 return false;
21944
21945 if (customsfxdata[slot].data == NULL)
21946 return false;
21947
21948 std::ofstream ofs(filename, std::ios::binary);
21949 if (!ofs)
21950 return false;
21951 ofs.write("RIFF",4);
21952 uint32_t samplerate = customsfxdata[slot].freq;
21953 uint16_t channels = customsfxdata[slot].stereo ? 2 : 1;
21954 uint32_t datalen = customsfxdata[slot].len*channels*customsfxdata[slot].bits / 8;
21955 uint32_t size = 36 + datalen;
21956 ofs.write((char *)&size, 4);
21957 ofs.write("WAVE", 4);
21958 ofs.write("fmt ", 4);
21959 uint32_t fmtlen = 16;
21960 ofs.write((char *)&fmtlen, 4);
21961 uint16_t type = 1;
21962 ofs.write((char *)&type, 2);
21963 ofs.write((char *)&channels, 2);
21964 ofs.write((char *)&samplerate, 4);
21965 uint32_t bytespersec = samplerate*channels*customsfxdata[slot].bits / 8;
21966 ofs.write((char *)&bytespersec, 4);
21967 uint16_t blockalign = channels*customsfxdata[slot].bits / 8;
21968 ofs.write((char *)&blockalign, 2);
21969 uint16_t bitspersample = customsfxdata[slot].bits;
21970 ofs.write((char *)&bitspersample, 2);
21971 ofs.write("data", 4);
21972 ofs.write((char *)&datalen, 4);
21973 if (bitspersample == 8)
21974 {
21975 for (int32_t i = 0; i < (int32_t)customsfxdata[slot].len*channels; i++)
21976 {
21977 char data = ((char *)customsfxdata[slot].data)[i];
21978 data ^= 0x80;
21979 ofs.write(&data, 1);
21980 }
21981 }
21982 else if (bitspersample == 16)
21983 {
21984 for (int32_t i = 0; i < (int32_t)customsfxdata[slot].len*channels; i++)
21985 {
21986 uint16_t data = ((uint16_t *)customsfxdata[slot].data)[i];
21987 data ^= 0x8000;
21988 ofs.write((char *)&data, 2);
21989 }
21990 }
21991 else
21992 return false;
21993 return !!ofs;
21994 }
21995
21996 int32_t onEditSFX(int32_t index)
21997 {
21998 call_sfxdata_dialog(index);
21999 return D_O_K;
22000 }
22001
22002 int32_t onMapStyles()
22003 {
22004 call_mapstyles_dialog();
22005 return D_O_K;
22006 }
22007
22008 int32_t d_misccolors_old_proc(int32_t msg,DIALOG *d,int32_t c)
22009 {
22010 //these are here to bypass compiler warnings about unused arguments
22011 c=c;
22012
22013 if(msg==MSG_DRAW)
22014 {
22015 textout_ex(screen,font,"0123456789ABCDEF",d->x+8,d->y,d->fg,d->bg);
22016 textout_ex(screen,font,"0",d->x,d->y+8,d->fg,d->bg);
22017 textout_ex(screen,font,"1",d->x,d->y+16,d->fg,d->bg);
22018 textout_ex(screen,font,"5",d->x,d->y+24,d->fg,d->bg);
22019
22020 for(int32_t i=0; i<32; i++)
22021 {
22022 int32_t px2 = d->x+((i&15)<<3)+8;
22023 int32_t py2 = d->y+((i>>4)<<3)+8;
22024 rectfill(screen,px2,py2,px2+7,py2+7,i);
22025 }
22026
22027 for(int32_t i=0; i<16; i++)
22028 {
22029 int32_t px2 = d->x+(i<<3)+8;
22030 rectfill(screen,px2,d->y+24,px2+7,d->y+31,i+80);
22031 }
22032 }
22033
22034 return D_O_K;
22035 }
22036
22037 int32_t hexclicked=-1;
22038
22039 int32_t d_misccolors_hexedit_proc(int32_t msg,DIALOG *d,int32_t c)
22040 {
22041 switch(msg)
22042 {
22043 case MSG_GOTFOCUS:
22044 hexclicked=((int32_t)(size_t)(d->dp3))+20;
22045 break;
22046
22047 case MSG_LOSTFOCUS:
22048 hexclicked=-1;
22049 break;
22050 }
22051
22052 return d_hexedit_proc(msg,d,c);
22053 }
22054
22055
22056 int32_t d_misccolors_proc(int32_t msg,DIALOG *d,int32_t c);
22057
22058 static int32_t misccolor1_list[] =
22059 {
22060 // dialog control number
22061 4, 5, 6, 7, 8, 20, 21, 22, 23, 24, 36, 37, 38, 39, 40, -1
22062 };
22063
22064 static int32_t misccolor2_list[] =
22065 {
22066 // dialog control number
22067 9, 10, 11, 12, 13, 25, 26, 27, 28, 29, 41, 42, 43, 44, 45, -1
22068 };
22069
22070 static int32_t misccolor3_list[] =
22071 {
22072 // dialog control number
22073 14, 15, 16, 17, 18, 30, 31, 32, 33, 34, 46, 47, 48, 49, 50, -1
22074 };
22075
22076 static int32_t misccolor4_list[] =
22077 {
22078 19, 35, 51, 54, 55, 56, -1
22079 };
22080
22081 static TABPANEL misccolor_tabs[] =
22082 {
22083 // (text)
22084 { (char *)"1", D_SELECTED, misccolor1_list, 0, NULL },
22085 { (char *)"2", 0, misccolor2_list, 0, NULL },
22086 { (char *)"3", 0, misccolor3_list, 0, NULL },
22087 { (char *)"4", 0, misccolor4_list, 0, NULL },
22088 { NULL, 0, NULL, 0, NULL }
22089 };
22090
22091 int32_t d_misccolors_tab_proc(int32_t msg,DIALOG *d,int32_t c);
22092
22093 static DIALOG misccolors_dlg[] =
22094 {
22095 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
22096 12 { jwin_win_proc, 2, 21, 316, 197-23, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Misc Colors", NULL, NULL },
22097 // { jwin_frame_proc, 98-84+1+2, 52+8-6+4, 132, 100, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
22098 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22099 12 { d_misccolors_proc, 92-84+1+2, 44+8-6+4, 128+8, 96+8, vc(9), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
22100 //3
22101 12 { d_misccolors_tab_proc, 150+14-2+10-15, 60-14, 150-10+15, 144-20-10, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, (void *) misccolor_tabs, NULL, (void *)misccolors_dlg },
22102 //4
22103 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Text:", NULL, NULL },
22104 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Caption:", NULL, NULL },
22105 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Overworld Minmap:", NULL, NULL },
22106 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Background:", NULL, NULL },
22107 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Foreground 1:", NULL, NULL },
22108 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Foreground 2:", NULL, NULL },
22109 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "BS Minimap Dark:", NULL, NULL },
22110 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "BS Minimap Goal:", NULL, NULL },
22111 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Compass Mark (Light):", NULL, NULL },
22112 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Compass Mark (Dark):", NULL, NULL },
22113 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Subscreen Background:", NULL, NULL },
22114 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Subscreen Shadow:", NULL, NULL },
22115 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Triforce Frame:", NULL, NULL },
22116 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Big Map Background:", NULL, NULL },
22117 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Big Map Foreground:", NULL, NULL },
22118 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hero's Position:", NULL, NULL },
22119
22120 //20
22121 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)0, },
22122 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)1, },
22123 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)2, },
22124 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)3, },
22125 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)4, },
22126 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)5, },
22127 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)6, },
22128 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)7, },
22129 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)8, },
22130 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)9, },
22131 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)10, },
22132 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)11, },
22133 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)12, },
22134 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)13, },
22135 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)14, },
22136 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)15, },
22137
22138 //36
22139 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22140 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22141 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22142 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22143 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22144 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22145 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22146 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22147 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22148 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22149 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22150 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22151 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22152 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22153 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22154 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22155
22156 //52
22157 12 { jwin_button_proc, 90, 190-20, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22158 12 { jwin_button_proc, 170, 190-20, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22159 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Message Text:", NULL, NULL },
22160 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)35, },
22161 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22162 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22163 };
22164
22165 int32_t d_misccolors_tab_proc(int32_t msg,DIALOG *d,int32_t c)
22166 {
22167
22168 switch(msg)
22169 {
22170 case MSG_WANTFOCUS:
22171 return D_WANTFOCUS;
22172 break;
22173 }
22174
22175 return jwin_tab_proc(msg,d,c);
22176 }
22177
22178
22179 int32_t d_misccolors_proc(int32_t msg,DIALOG *d,int32_t c)
22180 {
22181 //these are here to bypass compiler warnings about unused arguments
22182 c=c;
22183 int32_t mul=12;
22184
22185 switch(msg)
22186 {
22187 case MSG_CLICK:
22188 if(hexclicked!=-1)
22189 {
22190 int32_t color_col=vbound(((gui_mouse_x()-d->x-8)/mul),0,15);
22191 int32_t color_row=vbound(((gui_mouse_y()-d->y-10)/mul),0,11);
22192 sprintf((char*)misccolors_dlg[hexclicked].dp,"%X%X",color_row,color_col);
22193 object_message(misccolors_dlg+hexclicked,MSG_DRAW,0);
22194 }
22195
22196 break;
22197
22198 case MSG_DRAW:
22199 for(int32_t i=0; i<10; i++)
22200 {
22201 textprintf_centre_ex(screen,font,d->x+8+4+(i*mul),d->y,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%d", i);
22202 }
22203
22204 for(int32_t i=0; i<6; i++)
22205 {
22206 textprintf_centre_ex(screen,font,d->x+8+4+((10+i)*mul),d->y,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%c", i+'A');
22207 }
22208
22209 for(int32_t i=0; i<10; i++)
22210 {
22211 textprintf_right_ex(screen,font,d->x+6,d->y+(i*mul)+10,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%d", i);
22212 }
22213
22214 for(int32_t i=0; i<2; i++)
22215 {
22216 textprintf_right_ex(screen,font,d->x+6,d->y+((i+10)*mul)+10,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%c", i+'A');
22217 }
22218
22219 jwin_draw_frame(screen,d->x+6,d->y+8,int32_t(132*1.5)-2,int32_t(100*1.5)-2,FR_DEEP);
22220
22221 for(int32_t i=0; i<192; i++)
22222 {
22223 int32_t px2 = d->x+int32_t(((i&15)<<3)*1.5)+8;
22224 int32_t py2 = d->y+int32_t(((i>>4)<<3)*1.5)+8+2;
22225 rectfill(screen,px2,py2,px2+(mul-1),py2+(mul-1),i);
22226 }
22227
22228 break;
22229 }
22230
22231 return D_O_K;
22232 }
22233
22234
22235 int32_t onMiscColors()
22236 {
22237 char buf[17][3];
22238 byte *si = &(QMisc.colors.text);
22239 misccolors_dlg[0].dp2=get_zc_font(font_lfont);
22240
22241 for(int32_t i=0; i<16; i++)
22242 {
22243 sprintf(buf[i],"%02X",*(si++));
22244 sprintf(buf[16], "%02X", QMisc.colors.msgtext);
22245 misccolors_dlg[i+20].dp = buf[i];
22246 misccolors_dlg[55].dp = buf[16];
22247 }
22248
22249 large_dialog(misccolors_dlg);
22250
22251 if(do_zqdialog(misccolors_dlg,0)==52)
22252 {
22253 saved=false;
22254 si = &(QMisc.colors.text);
22255
22256 for(int32_t i=0; i<16; i++)
22257 {
22258 *si = zc_xtoi(buf[i]);
22259 ++si;
22260 }
22261
22262 QMisc.colors.msgtext = zc_xtoi(buf[16]);
22263 }
22264
22265 return D_O_K;
22266 }
22267
22268 // **** Palette cycling ****
22269
22270 static int32_t palclk[3];
22271 static int32_t palpos[3];
22272
22273 32 void reset_pal_cycling()
22274 {
22275
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 32 times.
128 for(int32_t i=0; i<3; i++)
22276 96 palclk[i]=palpos[i]=0;
22277 32 }
22278
22279 void cycle_palette()
22280 {
22281 if(!get_qr(qr_FADE))
22282 return;
22283
22284 int32_t level = Map.CurrScr()->color;
22285 bool refreshpal = false;
22286
22287 for(int32_t i=0; i<3; i++)
22288 {
22289 palcycle c = QMisc.cycles[level][i];
22290
22291 if(c.count&0xF0)
22292 {
22293 if(++palclk[i] >= c.speed)
22294 {
22295 palclk[i]=0;
22296
22297 if(++palpos[i] >= (c.count>>4))
22298 palpos[i]=0;
22299
22300 byte *si = colordata + CSET(level*pdLEVEL+poFADE1+1+palpos[i])*3;
22301
22302 si += (c.first&15)*3;
22303
22304 for(int32_t col=c.first&15; col<=(c.count&15); col++)
22305 {
22306 RAMpal[CSET(c.first>>4)+col] = _RGB(si);
22307 si+=3;
22308 }
22309
22310 refreshpal = true;
22311 }
22312 }
22313 }
22314
22315 if(refreshpal)
22316 {
22317 rebuild_trans_table();
22318 zc_set_palette_range(RAMpal,0,192,false);
22319 }
22320 }
22321
22322
22323 void doHelp()
22324 {
22325 do_box_edit(helpstr, "ZQuest Help", true, true);
22326 }
22327
22328 int32_t onHelp()
22329 {
22330 restore_mouse();
22331 doHelp();
22332 return D_O_K;
22333 }
22334
22335 void doZstringshelp()
22336 {
22337 do_box_edit(zstringshelpstr, "ZStrings Help", true, true);
22338 }
22339
22340 int32_t onZstringshelp()
22341 {
22342 restore_mouse();
22343 doZstringshelp();
22344 return D_O_K;
22345 }
22346
22347 static DIALOG layerdata_dlg[] =
22348 {
22349 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
22350 { jwin_win_proc, 16-12, 20+32, 288+1+24, 200+1-32-16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Layer Data", NULL, NULL },
22351 { jwin_button_proc, 170, 180, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22352 { jwin_button_proc, 90, 180, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22353 // 3
22354 { jwin_rtext_proc, 72, 88, 40, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Map:", NULL, NULL },
22355 { jwin_rtext_proc, 72, 88+18, 48, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
22356 { jwin_rtext_proc, 72, 88+36, 56, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Transparent:", NULL, NULL },
22357 { jwin_ctext_proc, 89, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
22358 { jwin_ctext_proc, 89+40, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "2", NULL, NULL },
22359 { jwin_ctext_proc, 89+80, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "3", NULL, NULL },
22360 { jwin_ctext_proc, 89+120, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "4", NULL, NULL },
22361 { jwin_ctext_proc, 89+160, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "5", NULL, NULL },
22362 { jwin_ctext_proc, 89+200, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "6", NULL, NULL },
22363
22364 //12
22365 { jwin_edit_proc, 76, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22366 { d_hexedit_proc, 76, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22367 { jwin_check_proc, 76, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22368
22369 { jwin_edit_proc, 76+40, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22370 { d_hexedit_proc, 76+40, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22371 { jwin_check_proc, 76+40, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22372
22373 { jwin_edit_proc, 76+80, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22374 { d_hexedit_proc, 76+80, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22375 { jwin_check_proc, 76+80, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22376
22377 { jwin_edit_proc, 76+120, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22378 { d_hexedit_proc, 76+120, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22379 { jwin_check_proc, 76+120, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22380
22381 { jwin_edit_proc, 76+160, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22382 { d_hexedit_proc, 76+160, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22383 { jwin_check_proc, 76+160, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22384
22385 { jwin_edit_proc, 76+200, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22386 { d_hexedit_proc, 76+200, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22387 { jwin_check_proc, 76+200, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22388
22389 //30
22390 { jwin_button_proc, 76, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22391 { jwin_button_proc, 76+40, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22392 { jwin_button_proc, 76+80, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22393 { jwin_button_proc, 76+120, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22394 { jwin_button_proc, 76+160, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22395 { jwin_button_proc, 76+200, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22396
22397 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22398 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22399
22400 };
22401
22402 int32_t edit_layers(mapscr* tempscr)
22403 {
22404 char buf[6][2][8];
22405 layerdata_dlg[0].dp2 = get_zc_font(font_lfont);
22406
22407 for(int32_t x=0; x<6; x++)
22408 {
22409 sprintf(buf[x][0],"%d",tempscr->layermap[x]);
22410 sprintf(buf[x][1],"%02X",tempscr->layerscreen[x]);
22411 }
22412
22413 for(int32_t x=0; x<6; x++)
22414 {
22415 for(int32_t y=0; y<2; y++)
22416 {
22417 layerdata_dlg[(x*3)+y+12].dp = buf[x][y];
22418 }
22419 }
22420
22421 for(int32_t x=0; x<6; x++)
22422 {
22423 layerdata_dlg[(x*3)+2+12].flags = (tempscr->layeropacity[x]<255) ? D_SELECTED : 0;
22424 }
22425
22426 large_dialog(layerdata_dlg);
22427
22428 int32_t ret=do_zqdialog(layerdata_dlg,0);
22429
22430 if(ret>=2)
22431 {
22432 for(int32_t x=0; x<6; x++)
22433 {
22434
22435 tempscr->layermap[x]=atoi(buf[x][0]);
22436
22437 if(tempscr->layermap[x]>map_count)
22438 {
22439 tempscr->layermap[x]=0;
22440 }
22441
22442 tempscr->layerscreen[x]=zc_xtoi(buf[x][1]);
22443
22444 if(zc_xtoi(buf[x][1])>=MAPSCRS)
22445 {
22446 tempscr->layerscreen[x]=0;
22447 }
22448
22449 // tempscr->layeropacity[x]=layerdata_dlg[(x*9)+8+19].flags & D_SELECTED ? 128:255;
22450 tempscr->layeropacity[x]=layerdata_dlg[(x*3)+2+12].flags & D_SELECTED ? 128:255;
22451 }
22452
22453 // } else if (ret>72&&ret<79) {
22454 // return (ret-72);
22455 }
22456
22457 return ret;
22458 }
22459
22460 static DIALOG autolayer_dlg[] =
22461 {
22462 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
22463 { jwin_win_proc, 64, 32+48, 192+1, 184+1-64, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Autolayer Setup", NULL, NULL },
22464 { jwin_text_proc, 76, 56+48, 136, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map for layer ?: ", NULL, NULL },
22465 { jwin_edit_proc, 212, 56+48, 32, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22466 { jwin_check_proc, 76, 56+18+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Only Blank Screens", NULL, NULL },
22467 { jwin_button_proc, 90, 188-12, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22468
22469 //5
22470 { jwin_button_proc, 170, 188-12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22471 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
22472 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22473 { jwin_check_proc, 76, 56+28+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Only Blank Layers", NULL, NULL },
22474 { jwin_check_proc, 76, 56+38+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Overwrite Layers", NULL, NULL },
22475
22476 //10
22477 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22478 };
22479 enum
22480 {
22481 autolyr_blankscreens,
22482 autolyr_blanklayers,
22483 autolyr_any
22484 };
22485 void autolayer(mapscr* tempscr, int32_t layer, int32_t al[6][3])
22486 {
22487 char tbuf[80],mlayer[80];
22488 autolayer_dlg[0].dp2=get_zc_font(font_lfont);
22489 sprintf(tbuf, "Map for layer %d: ", layer+1);
22490 autolayer_dlg[1].dp=tbuf;
22491 sprintf(mlayer, "%d", tempscr->layermap[layer]);
22492 autolayer_dlg[2].dp=mlayer;
22493
22494 large_dialog(autolayer_dlg);
22495 int ret, sel = 8, fl = autolyr_blanklayers;
22496 bool running = true;
22497 do
22498 {
22499 SETFLAG(autolayer_dlg[3].flags, D_SELECTED, sel==3);
22500 SETFLAG(autolayer_dlg[8].flags, D_SELECTED, sel==8);
22501 SETFLAG(autolayer_dlg[9].flags, D_SELECTED, sel==9);
22502 switch(ret=do_zqdialog(autolayer_dlg,0))
22503 {
22504 case 4: //OK
22505 {
22506 int32_t lmap=vbound(atoi(mlayer),0,Map.getMapCount());
22507 al[layer][0]=lmap;
22508 tempscr->layermap[layer]=lmap;
22509 tempscr->layerscreen[layer]=Map.getCurrScr();
22510 al[layer][1]=fl;
22511 al[layer][2]=1;
22512 running = false;
22513 break;
22514 }
22515 case 0: case 5: //cancel
22516 running = false;
22517 break;
22518 case 3:
22519 sel = ret;
22520 fl = autolyr_blankscreens;
22521 break;
22522 case 8:
22523 sel = ret;
22524 fl = autolyr_blanklayers;
22525 break;
22526 case 9:
22527 sel = ret;
22528 fl = autolyr_any;
22529 break;
22530 }
22531 }
22532 while(ret != 0 && ret != 4 && ret != 5);
22533 }
22534
22535 int32_t onLayers()
22536 {
22537 mapscr tempscr=*Map.CurrScr();
22538 int32_t al[6][3]; //autolayer[layer][0=map, 1=autolyr_ type, 2=bool go]
22539
22540 for(int32_t i=0; i<6; i++)
22541 {
22542 al[i][0]=tempscr.layermap[i];
22543 al[i][1]=0;
22544 al[i][2]=0;
22545 }
22546
22547 int32_t ret;
22548
22549 do
22550 {
22551 ret=edit_layers(&tempscr);
22552
22553 if(ret>2) //autolayer button
22554 {
22555 autolayer(&tempscr, ret-30, al);
22556 }
22557 }
22558 while(ret>2); //autolayer button
22559
22560 if(ret==2) //OK
22561 {
22562 saved=false;
22563 TheMaps[Map.getCurrMap()*MAPSCRS+Map.getCurrScr()]=tempscr;
22564
22565 for(int32_t i=0; i<6; i++)
22566 {
22567 int32_t tm=tempscr.layermap[i]-1;
22568 int32_t ts=tempscr.layerscreen[i];
22569
22570 if(al[i][2])
22571 {
22572 map_infos[Map.getCurrMap()].autolayers[i] = al[i][0];
22573 for(int32_t j=0; j<128; j++)
22574 {
22575 auto& curmapscr = TheMaps[Map.getCurrMap()*MAPSCRS+j];
22576 if(al[i][1] == autolyr_blankscreens && (curmapscr.valid&mVALID))
22577 continue;
22578 else if(al[i][1] == autolyr_blanklayers && curmapscr.layermap[i])
22579 continue;
22580
22581 curmapscr.layermap[i]=al[i][0];
22582 curmapscr.layerscreen[i]=al[i][0]?j:0;
22583 }
22584 }
22585 }
22586 }
22587
22588 // Check that the working layer wasn't just disabled
22589 if(CurrentLayer>0 && tempscr.layermap[CurrentLayer-1]==0)
22590 CurrentLayer=0;
22591
22592 return D_O_K;
22593 }
22594
22595
22596 char *itoa(int32_t i)
22597 {
22598 static char itoaret[500];
22599 sprintf(itoaret, "%d", i);
22600 return itoaret;
22601 }
22602
22603 21 void fps_callback()
22604 {
22605 21 lastfps=framecnt;
22606 21 framecnt=0;
22607 21 }
22608
22609 END_OF_FUNCTION(fps_callback)
22610
22611 //uint32_t col_diff[3*128];
22612 /*
22613 void bestfit_init(void)
22614 {
22615 int32_t i;
22616
22617 for (i=1; i<64; i++)
22618
22619 {
22620 int32_t k = i * i;
22621 col_diff[0 +i] = col_diff[0 +128-i] = k * (59 * 59);
22622 col_diff[128+i] = col_diff[128+128-i] = k * (30 * 30);
22623 col_diff[256+i] = col_diff[256+128-i] = k * (11 * 11);
22624 }
22625 }
22626 */
22627 21 void create_rgb_table2(RGB_MAP *table, AL_CONST PALETTE pal_8bit, void (*callback)(int32_t pos))
22628 {
22629 #define UNUSED 65535
22630 #define LAST 65532
22631
22632 // Allegro has been modified to use an 8 bit palette, but this method and RGB_MAP still use 6 bit.
22633 PALETTE pal;
22634
2/2
✓ Branch 0 taken 5376 times.
✓ Branch 1 taken 21 times.
5397 for (int i = 0; i < 256; i++)
22635 {
22636 5376 pal[i] = pal_8bit[i];
22637 5376 pal[i].r /= 4;
22638 5376 pal[i].g /= 4;
22639 5376 pal[i].b /= 4;
22640 5376 }
22641
22642 /* macro add adds to single linked list */
22643 #define add(i) (next[(i)] == UNUSED ? (next[(i)] = LAST, \
22644 (first != LAST ? (next[last] = (i)) : (first = (i))), \
22645 (last = (i))) : 0)
22646
22647 /* same but w/o checking for first element */
22648 #define add1(i) (next[(i)] == UNUSED ? (next[(i)] = LAST, \
22649 next[last] = (i), \
22650 (last = (i))) : 0)
22651 /* calculates distance between two colors */
22652 #define dist(a1, a2, a3, b1, b2, b3) \
22653 (col_diff[ ((a2) - (b2)) & 0x7F] + \
22654 (col_diff + 128)[((a1) - (b1)) & 0x7F] + \
22655 (col_diff + 256)[((a3) - (b3)) & 0x7F])
22656
22657 /* converts r,g,b to position in array and back */
22658 #define pos(r, g, b) \
22659 (((r) / 2) * 32 * 32 + ((g) / 2) * 32 + ((b) / 2))
22660
22661 #define depos(pal, r, g, b) \
22662 ((b) = ((pal) & 31) * 2, \
22663 (g) = (((pal) >> 5) & 31) * 2, \
22664 (r) = (((pal) >> 10) & 31) * 2)
22665
22666 /* is current color better than pal1? */
22667 #define better(r1, g1, b1, pal1) \
22668 (((int32_t)dist((r1), (g1), (b1), \
22669 (pal1).r, (pal1).g, (pal1).b)) > (int32_t)dist2)
22670
22671 /* checking of position */
22672 #define dopos(rp, gp, bp, ts) \
22673 if ((rp > -1 || r > 0) && (rp < 1 || r < 61) && \
22674 (gp > -1 || g > 0) && (gp < 1 || g < 61) && \
22675 (bp > -1 || b > 0) && (bp < 1 || b < 61)) \
22676 { \
22677 i = first + rp * 32 * 32 + gp * 32 + bp; \
22678 if (!data[i]) \
22679 { \
22680 data[i] = val; \
22681 add1(i); \
22682 } \
22683 else if ((ts) && (data[i] != val)) \
22684 { \
22685 dist2 = (rp ? (col_diff+128)[(r+2*rp-pal[val].r) & 0x7F] : r2) + \
22686 (gp ? (col_diff )[(g+2*gp-pal[val].g) & 0x7F] : g2) + \
22687 (bp ? (col_diff+256)[(b+2*bp-pal[val].b) & 0x7F] : b2); \
22688 if (better((r+2*rp), (g+2*gp), (b+2*bp), pal[data[i]])) \
22689 { \
22690 data[i] = val; \
22691 add1(i); \
22692 } \
22693 } \
22694 }
22695
22696 int32_t i, curr, r, g, b, val, dist2;
22697 uint32_t r2, g2, b2;
22698 uint16_t next[32*32*32];
22699 uint8_t *data;
22700 21 int32_t first = LAST;
22701 21 int32_t last = LAST;
22702 21 int32_t count = 0;
22703 21 int32_t cbcount = 0;
22704
22705 #define AVERAGE_COUNT 18000
22706
22707
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 10 times.
21 if(col_diff[1] == 0)
22708 11 bestfit_init();
22709
22710 21 memset(next, 255, sizeof(next));
22711 21 memset(table->data, 0, sizeof(char)*32*32*32);
22712
22713
22714 21 data = (uint8_t *)table->data;
22715
22716 /* add starting seeds for floodfill */
22717
2/2
✓ Branch 0 taken 5355 times.
✓ Branch 1 taken 21 times.
5376 for(i=1; i<PAL_SIZE; i++)
22718 {
22719 5355 curr = pos(pal[i].r, pal[i].g, pal[i].b);
22720
22721
2/2
✓ Branch 0 taken 4053 times.
✓ Branch 1 taken 1302 times.
5355 if(next[curr] == UNUSED)
22722 {
22723 1302 data[curr] = i;
22724
3/4
✓ Branch 0 taken 1302 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1281 times.
✓ Branch 3 taken 21 times.
1302 add(curr);
22725 1302 }
22726 5355 }
22727
22728 /* main floodfill: two versions of loop for faster growing in blue axis */
22729 // while (first != LAST) {
22730
2/2
✓ Branch 0 taken 450575 times.
✓ Branch 1 taken 21 times.
450596 while(first < LAST)
22731 {
22732 450575 depos(first, r, g, b);
22733
22734 /* calculate distance of current color */
22735 450575 val = data[first];
22736 450575 r2 = (col_diff+128)[((pal[val].r)-(r)) & 0x7F];
22737 450575 g2 = (col_diff)[((pal[val].g)-(g)) & 0x7F];
22738 450575 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
22739
22740 /* try to grow to all directions */
22741 #ifdef _MSC_VER
22742 #pragma warning(disable:4127)
22743 #endif
22744
11/12
✓ Branch 0 taken 14797 times.
✓ Branch 1 taken 435778 times.
✓ Branch 2 taken 418414 times.
✓ Branch 3 taken 17364 times.
✓ Branch 4 taken 17364 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349903 times.
✓ Branch 7 taken 68511 times.
✓ Branch 8 taken 19107 times.
✓ Branch 9 taken 49404 times.
✓ Branch 10 taken 30562 times.
✓ Branch 11 taken 18842 times.
868989 dopos(0, 0, 1, 1);
22745
11/12
✓ Branch 0 taken 13307 times.
✓ Branch 1 taken 437268 times.
✓ Branch 2 taken 421926 times.
✓ Branch 3 taken 15342 times.
✓ Branch 4 taken 15342 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 367287 times.
✓ Branch 7 taken 54639 times.
✓ Branch 8 taken 21549 times.
✓ Branch 9 taken 33090 times.
✓ Branch 10 taken 21770 times.
✓ Branch 11 taken 11320 times.
872501 dopos(0, 0,-1, 1);
22746
11/12
✓ Branch 0 taken 14382 times.
✓ Branch 1 taken 436193 times.
✓ Branch 2 taken 424908 times.
✓ Branch 3 taken 11285 times.
✓ Branch 4 taken 11285 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 347042 times.
✓ Branch 7 taken 77866 times.
✓ Branch 8 taken 50354 times.
✓ Branch 9 taken 27512 times.
✓ Branch 10 taken 17286 times.
✓ Branch 11 taken 10226 times.
875483 dopos(1, 0, 0, 1);
22747
11/12
✓ Branch 0 taken 14499 times.
✓ Branch 1 taken 436076 times.
✓ Branch 2 taken 424084 times.
✓ Branch 3 taken 11992 times.
✓ Branch 4 taken 11992 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349660 times.
✓ Branch 7 taken 74424 times.
✓ Branch 8 taken 49118 times.
✓ Branch 9 taken 25306 times.
✓ Branch 10 taken 16008 times.
✓ Branch 11 taken 9298 times.
874659 dopos(-1, 0, 0, 1);
22748
11/12
✓ Branch 0 taken 14539 times.
✓ Branch 1 taken 436036 times.
✓ Branch 2 taken 391471 times.
✓ Branch 3 taken 44565 times.
✓ Branch 4 taken 44565 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 290643 times.
✓ Branch 7 taken 100828 times.
✓ Branch 8 taken 83046 times.
✓ Branch 9 taken 17782 times.
✓ Branch 10 taken 11492 times.
✓ Branch 11 taken 6290 times.
842046 dopos(0, 1, 0, 1);
22749
11/12
✓ Branch 0 taken 13124 times.
✓ Branch 1 taken 437451 times.
✓ Branch 2 taken 399232 times.
✓ Branch 3 taken 38219 times.
✓ Branch 4 taken 38219 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 299384 times.
✓ Branch 7 taken 99848 times.
✓ Branch 8 taken 85123 times.
✓ Branch 9 taken 14725 times.
✓ Branch 10 taken 9189 times.
✓ Branch 11 taken 5536 times.
849807 dopos(0,-1, 0, 1);
22750 #ifdef _MSC_VER
22751 #pragma warning(default:4127)
22752 #endif
22753
22754 /* faster growing of blue direction */
22755
4/4
✓ Branch 0 taken 437268 times.
✓ Branch 1 taken 13307 times.
✓ Branch 2 taken 21549 times.
✓ Branch 3 taken 415719 times.
450575 if((b > 0) && (data[first-1] == val))
22756 {
22757 415719 b -= 2;
22758 415719 first--;
22759 415719 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
22760
22761 #ifdef _MSC_VER
22762 #pragma warning(disable:4127)
22763 #endif
22764
5/6
✓ Branch 0 taken 13508 times.
✓ Branch 1 taken 402211 times.
✓ Branch 2 taken 366059 times.
✓ Branch 3 taken 36152 times.
✓ Branch 4 taken 36152 times.
✗ Branch 5 not taken.
781778 dopos(-1, 0, 0, 0);
22765
5/6
✓ Branch 0 taken 13364 times.
✓ Branch 1 taken 402355 times.
✓ Branch 2 taken 365610 times.
✓ Branch 3 taken 36745 times.
✓ Branch 4 taken 36745 times.
✗ Branch 5 not taken.
781329 dopos(1, 0, 0, 0);
22766
5/6
✓ Branch 0 taken 12197 times.
✓ Branch 1 taken 403522 times.
✓ Branch 2 taken 355860 times.
✓ Branch 3 taken 47662 times.
✓ Branch 4 taken 47662 times.
✗ Branch 5 not taken.
771579 dopos(0,-1, 0, 0);
22767
5/6
✓ Branch 0 taken 13551 times.
✓ Branch 1 taken 402168 times.
✓ Branch 2 taken 336590 times.
✓ Branch 3 taken 65578 times.
✓ Branch 4 taken 65578 times.
✗ Branch 5 not taken.
752309 dopos(0, 1, 0, 0);
22768 #ifdef _MSC_VER
22769 #pragma warning(default:4127)
22770 #endif
22771
22772 415719 first++;
22773 415719 }
22774
22775 /* get next from list */
22776 450575 i = first;
22777 450575 first = next[first];
22778 450575 next[i] = UNUSED;
22779
22780 /* second version of loop */
22781 // if (first != LAST) {
22782
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 450564 times.
450575 if(first < LAST)
22783 {
22784
22785 450564 depos(first, r, g, b);
22786
22787 450564 val = data[first];
22788 450564 r2 = (col_diff+128)[((pal[val].r)-(r)) & 0x7F];
22789 450564 g2 = (col_diff)[((pal[val].g)-(g)) & 0x7F];
22790 450564 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
22791
22792 #ifdef _MSC_VER
22793 #pragma warning(disable:4127)
22794 #endif
22795
11/12
✓ Branch 0 taken 14370 times.
✓ Branch 1 taken 436194 times.
✓ Branch 2 taken 415857 times.
✓ Branch 3 taken 20337 times.
✓ Branch 4 taken 20337 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 347408 times.
✓ Branch 7 taken 68449 times.
✓ Branch 8 taken 19063 times.
✓ Branch 9 taken 49386 times.
✓ Branch 10 taken 30486 times.
✓ Branch 11 taken 18900 times.
866421 dopos(0, 0, 1, 1);
22796
11/12
✓ Branch 0 taken 13244 times.
✓ Branch 1 taken 437320 times.
✓ Branch 2 taken 424306 times.
✓ Branch 3 taken 13014 times.
✓ Branch 4 taken 13014 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 369421 times.
✓ Branch 7 taken 54885 times.
✓ Branch 8 taken 21923 times.
✓ Branch 9 taken 32962 times.
✓ Branch 10 taken 21778 times.
✓ Branch 11 taken 11184 times.
874870 dopos(0, 0,-1, 1);
22797
11/12
✓ Branch 0 taken 14583 times.
✓ Branch 1 taken 435981 times.
✓ Branch 2 taken 424300 times.
✓ Branch 3 taken 11681 times.
✓ Branch 4 taken 11681 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 346291 times.
✓ Branch 7 taken 78009 times.
✓ Branch 8 taken 50641 times.
✓ Branch 9 taken 27368 times.
✓ Branch 10 taken 17229 times.
✓ Branch 11 taken 10139 times.
874864 dopos(1, 0, 0, 1);
22798
11/12
✓ Branch 0 taken 14345 times.
✓ Branch 1 taken 436219 times.
✓ Branch 2 taken 424380 times.
✓ Branch 3 taken 11839 times.
✓ Branch 4 taken 11839 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349785 times.
✓ Branch 7 taken 74595 times.
✓ Branch 8 taken 49492 times.
✓ Branch 9 taken 25103 times.
✓ Branch 10 taken 16289 times.
✓ Branch 11 taken 8814 times.
874944 dopos(-1, 0, 0, 1);
22799
11/12
✓ Branch 0 taken 14476 times.
✓ Branch 1 taken 436088 times.
✓ Branch 2 taken 392433 times.
✓ Branch 3 taken 43655 times.
✓ Branch 4 taken 43655 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 292163 times.
✓ Branch 7 taken 100270 times.
✓ Branch 8 taken 82655 times.
✓ Branch 9 taken 17615 times.
✓ Branch 10 taken 11555 times.
✓ Branch 11 taken 6060 times.
842997 dopos(0, 1, 0, 1);
22800
11/12
✓ Branch 0 taken 13010 times.
✓ Branch 1 taken 437554 times.
✓ Branch 2 taken 399976 times.
✓ Branch 3 taken 37578 times.
✓ Branch 4 taken 37578 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 299995 times.
✓ Branch 7 taken 99981 times.
✓ Branch 8 taken 85368 times.
✓ Branch 9 taken 14613 times.
✓ Branch 10 taken 9367 times.
✓ Branch 11 taken 5246 times.
850540 dopos(0,-1, 0, 1);
22801 #ifdef _MSC_VER
22802 #pragma warning(default:4127)
22803 #endif
22804
22805
4/4
✓ Branch 0 taken 436194 times.
✓ Branch 1 taken 14370 times.
✓ Branch 2 taken 19063 times.
✓ Branch 3 taken 417131 times.
450564 if((b < 61) && (data[first + 1] == val))
22806 {
22807 417131 b += 2;
22808 417131 first++;
22809 417131 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7f];
22810 #ifdef _MSC_VER
22811 #pragma warning(disable:4127)
22812 #endif
22813
5/6
✓ Branch 0 taken 13397 times.
✓ Branch 1 taken 403734 times.
✓ Branch 2 taken 361902 times.
✓ Branch 3 taken 41832 times.
✓ Branch 4 taken 41832 times.
✗ Branch 5 not taken.
779033 dopos(-1, 0, 0, 0);
22814
5/6
✓ Branch 0 taken 13497 times.
✓ Branch 1 taken 403634 times.
✓ Branch 2 taken 354721 times.
✓ Branch 3 taken 48913 times.
✓ Branch 4 taken 48913 times.
✗ Branch 5 not taken.
771852 dopos(1, 0, 0, 0);
22815
5/6
✓ Branch 0 taken 12034 times.
✓ Branch 1 taken 405097 times.
✓ Branch 2 taken 338219 times.
✓ Branch 3 taken 66878 times.
✓ Branch 4 taken 66878 times.
✗ Branch 5 not taken.
755350 dopos(0,-1, 0, 0);
22816
5/6
✓ Branch 0 taken 13617 times.
✓ Branch 1 taken 403514 times.
✓ Branch 2 taken 337319 times.
✓ Branch 3 taken 66195 times.
✓ Branch 4 taken 66195 times.
✗ Branch 5 not taken.
754450 dopos(0, 1, 0, 0);
22817 #ifdef _MSC_VER
22818 #pragma warning(default:4127)
22819 #endif
22820
22821 417131 first--;
22822 417131 }
22823
22824 450564 i = first;
22825 450564 first = next[first];
22826 450564 next[i] = UNUSED;
22827 450564 }
22828
22829 450575 count++;
22830
22831
2/2
✓ Branch 0 taken 445178 times.
✓ Branch 1 taken 5397 times.
450575 if(count == (cbcount+1)*AVERAGE_COUNT/256)
22832 {
22833
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 5376 times.
5397 if(cbcount < 256)
22834 {
22835
1/2
✓ Branch 0 taken 5376 times.
✗ Branch 1 not taken.
5376 if(callback)
22836 callback(cbcount);
22837
22838 5376 cbcount++;
22839 5376 }
22840 5397 }
22841
22842 }
22843
22844 /* only the transparent (pink) color can be mapped to index 0 */
22845
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
21 if((pal[0].r == 63) && (pal[0].g == 0) && (pal[0].b == 63))
22846 table->data[31][0][31] = 0;
22847
22848
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(callback)
22849 while(cbcount < 256)
22850 callback(cbcount++);
22851 21 }
22852
22853 21 void rebuild_trans_table()
22854 {
22855 21 create_rgb_table2(&zq_rgb_table, RAMpal, NULL);
22856 21 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
22857 21 memcpy(&trans_table2, &trans_table, sizeof(COLOR_MAP));
22858
22859
2/2
✓ Branch 0 taken 5376 times.
✓ Branch 1 taken 21 times.
5397 for(int32_t q=0; q<PAL_SIZE; q++)
22860 {
22861 5376 trans_table2.data[0][q] = q;
22862 5376 trans_table2.data[q][q] = q;
22863 5376 }
22864 21 }
22865
22866 int32_t isFullScreen()
22867 {
22868 return !is_windowed_mode();
22869 }
22870
22871 void hit_close_button()
22872 {
22873 close_button_quit=true;
22874 return;
22875 }
22876
22877 extern bool dirty_screen;
22878
22879 void anim_hw_screen(bool force)
22880 {
22881 // if (force || myvsync)
22882 {
22883 ++cpoolbrush_index;
22884
22885 if(prv_mode)
22886 {
22887 if(Map.get_prvtime())
22888 {
22889 Map.set_prvtime(Map.get_prvtime()-1);
22890
22891 if(!Map.get_prvtime())
22892 {
22893 prv_warp=1;
22894 }
22895 }
22896 }
22897 if(AnimationOn)
22898 {
22899 animate_combos();
22900 update_freeform_combos();
22901 }
22902
22903 if(CycleOn)
22904 cycle_palette();
22905
22906 animate_coords();
22907 update_hw_screen();
22908 }
22909 }
22910
22911 void custom_vsync()
22912 {
22913 anim_hw_screen(true);
22914 }
22915
22916 void switch_out()
22917 {
22918 zcmusic_pause(zcmusic, ZCM_PAUSE);
22919 zc_midi_pause();
22920 }
22921
22922 void switch_in()
22923 {
22924 if(exiting_program)
22925 return;
22926 zcmusic_pause(zcmusic, ZCM_RESUME);
22927 zc_midi_resume();
22928 }
22929
22930 void Z_eventlog(const char *format,...)
22931 {
22932 format=format; //to prevent a compiler warning
22933 }
22934
22935 int32_t get_currdmap()
22936 {
22937 return zinit.start_dmap;
22938 }
22939
22940 int32_t get_dlevel()
22941 {
22942 return DMaps[zinit.start_dmap].level;
22943 }
22944
22945 int32_t get_currscr()
22946 {
22947 return Map.getCurrScr();
22948 }
22949
22950 int32_t get_currmap()
22951 {
22952 return Map.getCurrMap();
22953 }
22954
22955 int32_t get_homescr()
22956 {
22957 return DMaps[zinit.start_dmap].cont;
22958 }
22959
22960 int get_screen_for_world_xy(int x, int y)
22961 {
22962 return -1;
22963 }
22964
22965 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
22966 {
22967 //TODO remove as special case?? -DD
22968 if(item_type==itype_shield)
22969 {
22970 return 2;
22971 }
22972
22973 int id = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
22974 return id > -1 ? itemsbuf[id].level : 0;
22975 }
22976
22977 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
22978 {
22979 if (game)
22980 {
22981 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
22982 return (result<0) ? 0 : itemsbuf[result].power;
22983 }
22984 return 1;
22985 }
22986
22987 int32_t current_item_id(int32_t itemtype, bool, bool, bool)
22988 {
22989 if (game)
22990 {
22991 int32_t result = -1;
22992 int32_t highestlevel = -1;
22993
22994 for (int32_t i = 0; i < MAXITEMS; i++)
22995 {
22996 if ((zq_ignore_item_ownership || game->get_item(i)) && itemsbuf[i].type == itemtype)
22997 {
22998 if (itemsbuf[i].level >= highestlevel)
22999 {
23000 highestlevel = itemsbuf[i].level;
23001 result = i;
23002 }
23003 }
23004 }
23005 return result;
23006 }
23007 for(int32_t i=0; i<MAXITEMS; i++)
23008 {
23009 if(itemsbuf[i].type==itemtype)
23010 return i;
23011 }
23012
23013 return -1;
23014 }
23015
23016
23017 bool can_use_item(int32_t item_type, int32_t item)
23018 {
23019 //these are here to bypass compiler warnings about unused arguments
23020 item_type=item_type;
23021 item=item;
23022
23023 return true;
23024 }
23025
23026 bool has_item(int32_t item_type, int32_t it)
23027 {
23028 //these are here to bypass compiler warnings about unused arguments
23029 item_type=item_type;
23030 it=it;
23031
23032 return true;
23033 }
23034
23035 int32_t get_bmaps(int32_t si)
23036 {
23037 //these are here to bypass compiler warnings about unused arguments
23038 si=si;
23039
23040 return 255;
23041 }
23042
23043 bool no_subscreen()
23044 {
23045 return false;
23046 }
23047
23048 12 static void allocate_crap()
23049 {
23050 12 filepath=(char*)malloc(2048);
23051 12 datapath=(char*)malloc(2048);
23052 12 midipath=(char*)malloc(2048);
23053 12 imagepath=(char*)malloc(2048);
23054 12 tmusicpath=(char*)malloc(2048);
23055 12 last_timed_save=(char*)malloc(2048);
23056
23057
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!filepath || !datapath || !imagepath || !midipath || !tmusicpath || !last_timed_save)
23058 {
23059 Z_error_fatal("Error: no memory for file paths!");
23060 }
23061
23062
23063 12 customtunes = (zctune*)malloc(sizeof(zctune)*MAXCUSTOMMIDIS_ZQ);
23064 12 memset(customtunes, 0, sizeof(zctune)*MAXCUSTOMMIDIS_ZQ);
23065
23066
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; ++i)
23067 {
23068 3072 customtunes[i].data=NULL;
23069 3072 }
23070
23071
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMTUNES; i++)
23072 {
23073 3024 midi_string[i+4]=customtunes[i].title;
23074 3024 screen_midi_string[i+5]=customtunes[i].title;
23075 3024 }
23076
23077
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<WAV_COUNT; i++)
23078 {
23079
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(sfx_string[i]!=NULL) delete sfx_string[i];
23080 3072 customsfxdata[i].data=NULL;
23081 3072 sfx_string[i] = new char[36];
23082 3072 memset(sfx_string[i], 0, 36);
23083 3072 }
23084
23085
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
23086 {
23087
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(weapon_string[i]!=NULL) delete weapon_string[i];
23088 3072 weapon_string[i] = new char[64];
23089 3072 memset(weapon_string[i], 0, 64);
23090 3072 }
23091
23092
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
23093 {
23094
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(item_string[i]!=NULL) delete item_string[i];
23095 3072 item_string[i] = new char[64];
23096 3072 memset(item_string[i], 0, 64);
23097 3072 }
23098
23099
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<eMAXGUYS; i++)
23100 {
23101
1/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6144 if(guy_string[i]!=NULL) delete guy_string[i];
23102 6144 guy_string[i] = new char[64];
23103 6144 memset(guy_string[i], 0, 64);
23104 6144 }
23105
23106
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
23107 {
23108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6144 times.
6144 delete ffscripts[i];
23109
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 ffscripts[i] = new script_data(ScriptType::FFC, i);
23110 6144 }
23111
23112
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
23113 {
23114
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete itemscripts[i];
23115
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 itemscripts[i] = new script_data(ScriptType::Item, i);
23116 3072 }
23117
23118
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
23119 {
23120
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete guyscripts[i];
23121
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 guyscripts[i] = new script_data(ScriptType::NPC, i);
23122 3072 }
23123
23124
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
23125 {
23126
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete screenscripts[i];
23127
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 screenscripts[i] = new script_data(ScriptType::Screen, i);
23128 3072 }
23129
23130
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
23131 {
23132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 delete globalscripts[i];
23133
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 globalscripts[i] = new script_data(ScriptType::Global, i);
23134 96 }
23135
23136
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
23137 {
23138
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 delete playerscripts[i];
23139
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 playerscripts[i] = new script_data(ScriptType::Hero, i);
23140 60 }
23141
23142
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
23143 {
23144
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete lwpnscripts[i];
23145
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 lwpnscripts[i] = new script_data(ScriptType::Lwpn, i);
23146 3072 }
23147
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
23148 {
23149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3072 times.
3072 delete ewpnscripts[i];
23150
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 ewpnscripts[i] = new script_data(ScriptType::Ewpn, i);
23151 3072 }
23152
23153
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
23154 {
23155
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete dmapscripts[i];
23156
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 dmapscripts[i] = new script_data(ScriptType::DMap, i);
23157 3072 }
23158
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
23159 {
23160
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete itemspritescripts[i];
23161
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 itemspritescripts[i] = new script_data(ScriptType::ItemSprite, i);
23162 3072 }
23163
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
23164 {
23165
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 delete comboscripts[i];
23166
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 comboscripts[i] = new script_data(ScriptType::Combo, i);
23167 6144 }
23168
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
23169 {
23170
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 delete genericscripts[i];
23171
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 genericscripts[i] = new script_data(ScriptType::Generic, i);
23172 6144 }
23173
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
23174 {
23175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3072 times.
3072 delete subscreenscripts[i];
23176
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 subscreenscripts[i] = new script_data(ScriptType::EngineSubscreen, i);
23177 3072 }
23178 12 }
23179
23180 static void handle_sentry_tags()
23181 {
23182 static bool sentry_first_time = true;
23183
23184 static MapCursor sentry_last_map_cursor;
23185 if (Map.getCursor() != sentry_last_map_cursor || sentry_first_time)
23186 {
23187 sentry_last_map_cursor = Map.getCursor();
23188 zapp_reporting_set_tag("cursor.map", sentry_last_map_cursor.map);
23189 zapp_reporting_set_tag("cursor.screen", sentry_last_map_cursor.screen);
23190 zapp_reporting_set_tag("cursor.viewscr", sentry_last_map_cursor.viewscr);
23191 zapp_reporting_set_tag("cursor.size", sentry_last_map_cursor.size);
23192 }
23193
23194 static bool sentry_last_is_compact;
23195 if (is_compact != sentry_last_is_compact || sentry_first_time)
23196 {
23197 sentry_last_is_compact = is_compact;
23198 zapp_reporting_set_tag("compact", sentry_last_is_compact);
23199 }
23200
23201 sentry_first_time = false;
23202 }
23203
23204 // Removes the top layer encoding from a quest file. See open_quest_file.
23205 // This has zero impact on the contents of the quest file. There should be no way for this to
23206 // break anything.
23207 static void do_unencrypt_qst_command(const char* input_filename, const char* output_filename)
23208 {
23209 // If the file is already an unencrypted packfile, there's nothing to do.
23210 PACKFILE* pf_check = pack_fopen_password(input_filename, F_READ_PACKED, "");
23211 pack_fclose(pf_check);
23212 if (pf_check) return;
23213
23214 int32_t error;
23215 PACKFILE* pf = open_quest_file(&error, input_filename, false);
23216 PACKFILE* pf2 = pack_fopen_password(output_filename, F_WRITE_PACKED, "");
23217 int c;
23218 while ((c = pack_getc(pf)) != EOF)
23219 {
23220 pack_putc(c, pf2);
23221 }
23222 pack_fclose(pf);
23223 pack_fclose(pf2);
23224 clear_quest_tmpfile();
23225 }
23226
23227 // This will remove the PACKFILE compression. Incidentally, it also removes the top encoding layer.
23228 static void do_uncompress_qst_command(const char* input_filename, const char* output_filename)
23229 {
23230 auto unencrypted_result = try_open_maybe_legacy_encoded_file(input_filename, ENC_STR, nullptr, QH_NEWIDSTR, QH_IDSTR);
23231 if (unencrypted_result.not_found)
23232 {
23233 printf("qst not found\n");
23234 zq_exit(1);
23235 }
23236 if (!unencrypted_result.compressed && !unencrypted_result.encrypted)
23237 {
23238 // If the file is already an uncompressed file, there's nothing to do but copy it.
23239 fs::copy(input_filename, output_filename);
23240 return;
23241 }
23242
23243 pack_fclose(unencrypted_result.decoded_pf);
23244
23245 int32_t error;
23246 PACKFILE* pf = open_quest_file(&error, input_filename, false);
23247 PACKFILE* pf2 = pack_fopen_password(output_filename, F_WRITE, "");
23248 int c;
23249 while ((c = pack_getc(pf)) != EOF)
23250 {
23251 pack_putc(c, pf2);
23252 }
23253 pack_fclose(pf);
23254 pack_fclose(pf2);
23255 clear_quest_tmpfile();
23256 }
23257
23258 // Copy a quest file by loading and resaving, exactly like if the user did it in the UI.
23259 // Note there could be changes introduced in the loading or saving functions. These are
23260 // typically for compatability, but could possibly be a source of bugs.
23261 3 static void do_copy_qst_command(const char* input_filename, const char* output_filename)
23262 {
23263 3 set_headless_mode();
23264
23265 // We need to init some stuff before loading a quest file will work.
23266 3 int fake_errno = 0;
23267 3 allegro_errno = &fake_errno;
23268 3 get_qst_buffers();
23269
23270 3 int ret = load_quest(input_filename, false);
23271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret)
23272 {
23273 zq_exit(ret);
23274 }
23275
23276 3 ret = save_quest(output_filename, false);
23277 3 zq_exit(ret);
23278 3 }
23279
23280 int32_t Awpn=-1, Bwpn=-1, Xwpn = -1, Ywpn = -1;
23281 84 sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations, portals;
23282 int32_t exittimer = 10000, exittimer2 = 100;
23283
23284 1 static bool partial_load_test(const char* test_dir)
23285 {
23286
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 auto classic_path = fs::path(test_dir) / "replays/classic_1st.qst";
23287
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 int ret = load_quest(classic_path.string().c_str(), false);
23288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
23289 {
23290 printf("failed to load classic_1st.qst: ret == %d\n", ret);
23291 return false;
23292 }
23293
23294 1 int cont = DMaps[0].cont;
23295
23296 // Skip same stuff as used in zq_tiles.cpp for grabbing tiles from a qst.
23297 byte skip_flags[4];
23298
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 26 times.
27 for (int i=0; i<skip_max; ++i)
23299
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 set_bit(skip_flags,i,1);
23300
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_bit(skip_flags,skip_tiles,0);
23301
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_bit(skip_flags,skip_header,0);
23302 1 zquestheader tempheader{};
23303
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 auto ptux_path = fs::path(test_dir) / "quests/PTUX.qst";
23304
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 ret = loadquest(ptux_path.string().c_str(), &tempheader, &QMisc, customtunes, false, skip_flags);
23305
23306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
23307 {
23308 printf("failed to load PTUX.qst: ret == %d\n", ret);
23309 return false;
23310 }
23311
23312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (DMaps[0].cont != cont)
23313 {
23314 printf("unexpected modification: DMaps[0].cont == %d, should be %d\n", DMaps[0].cont, cont);
23315 return false;
23316 }
23317
23318 // TODO should run replay. Currently, resaving classic_1st.qst fails its replay (see test_save in test_zeditor.py)
23319
23320 1 return true;
23321 1 }
23322
23323 template <typename ...Params>
23324 [[noreturn]] void FatalConsole(const char *format, Params&&... params)
23325 {
23326 FFCore.ZScriptConsole(CConsoleLoggerEx::COLOR_RED|CConsoleLoggerEx::COLOR_INTENSITY|CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"");
23327 Z_error_fatal(format, std::forward<Params>(params)...);
23328 }
23329
23330 40 static BITMAP* load_asset_bmp(const char* path)
23331 {
23332 40 BITMAP* bmp = load_bmp(path, nullptr);
23333
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (!bmp)
23334 Z_error_fatal("Failed to load required asset: %s\n", path);
23335 40 return bmp;
23336 }
23337
23338 8 static void load_asset_pal(PALETTE pal, const char* path)
23339 {
23340 8 BITMAP* bmp = load_bmp(path, pal);
23341
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!bmp)
23342 Z_error_fatal("Failed to load required asset: %s\n", path);
23343 8 }
23344
23345 8 static MIDI* load_asset_midi(const char* path)
23346 {
23347 8 MIDI* midi = load_midi(path);
23348
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!midi)
23349 Z_error_fatal("Failed to load required asset: %s\n", path);
23350 8 return midi;
23351 }
23352
23353 BITMAP* asset_icons_bmp;
23354 BITMAP* asset_engravings_bmp;
23355 BITMAP* asset_mouse_bmp;
23356 BITMAP* asset_select_bmp;
23357 BITMAP* asset_arrows_bmp;
23358 MIDI* asset_tunes_midi;
23359 PALETTE asset_pal;
23360
23361 8 static void load_assets()
23362 {
23363 8 asset_icons_bmp = load_asset_bmp("assets/editor/icons.bmp");
23364 8 asset_engravings_bmp = load_asset_bmp("assets/editor/engravings.bmp");
23365 8 asset_mouse_bmp = load_asset_bmp("assets/editor/mouse.bmp");
23366 8 asset_select_bmp = load_asset_bmp("assets/editor/select.bmp");
23367 8 asset_arrows_bmp = load_asset_bmp("assets/editor/arrows.bmp");
23368 8 asset_tunes_midi = load_asset_midi("assets/editor/tunes.mid");
23369 8 load_asset_pal(asset_pal, "assets/editor/pal.bmp");
23370 8 }
23371
23372 static bool application_has_loaded;
23373
23374 8 int32_t main(int32_t argc,char **argv)
23375 {
23376 8 int test_zc_arg = used_switch(argc, argv, "-test-zc");
23377
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (test_zc_arg > 0)
23378 1 set_headless_mode();
23379
23380 8 zalleg_setup_allegro(App::zquest, argc, argv);
23381 8 allocate_crap();
23382
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 set_should_zprint_cb([]() {
23383 return get_qr(qr_SCRIPTERRLOG) || DEVLEVEL > 0;
23384 });
23385
23386 8 int package_arg = used_switch(argc, argv, "-package");
23387
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (package_arg > 0)
23388 {
23389 if (package_arg + 3 > argc)
23390 {
23391 printf("%d\n", argc);
23392 printf("expected -package <game.qst> <package name>\n");
23393 zq_exit(1);
23394 }
23395
23396 const char* input_filename = argv[package_arg + 1];
23397 const char* package_name = argv[package_arg + 2];
23398 if (auto error = package_create(input_filename, package_name))
23399 Z_error_fatal("%s\n", error->c_str());
23400 zq_exit(0);
23401 }
23402
23403 8 int copy_qst_arg = used_switch(argc, argv, "-copy-qst");
23404
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
8 if (copy_qst_arg > 0)
23405 {
23406
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (copy_qst_arg + 3 > argc)
23407 {
23408 printf("%d\n", argc);
23409 printf("expected -copy-qst <input> <output>\n");
23410 zq_exit(1);
23411 }
23412
23413 3 const char* input_filename = argv[copy_qst_arg + 1];
23414 3 const char* output_filename = argv[copy_qst_arg + 2];
23415 3 do_copy_qst_command(input_filename, output_filename);
23416 3 }
23417
23418 8 Z_title("ZQuest Classic Editor, %s", getVersionString());
23419
23420
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!get_qst_buffers())
23421 {
23422 Z_error_fatal("Error");
23423 }
23424
23425 8 undocombobuf.clear();
23426 8 undocombobuf.resize(MAXCOMBOS);
23427
23428
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if((newundotilebuf=(tiledata*)malloc(NEWMAXTILES*sizeof(tiledata)))==NULL)
23429 {
23430 Z_error_fatal("Error: no memory for tile undo buffer!");
23431 }
23432
23433 8 memset(newundotilebuf, 0, NEWMAXTILES*sizeof(tiledata));
23434
23435 8 Z_message("Resetting new tile buffer...");
23436 8 newtilebuf = (tiledata*)malloc(NEWMAXTILES*sizeof(tiledata));
23437
23438
2/2
✓ Branch 0 taken 1930500 times.
✓ Branch 1 taken 8 times.
1930508 for(int32_t j=0; j<NEWMAXTILES; j++)
23439 1930500 newtilebuf[j].data=NULL;
23440
23441 8 Z_message("OK\n");
23442
23443 8 zc_srand(time(0));
23444
23445
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if (test_zc_arg > 0)
23446 {
23447 1 set_headless_mode();
23448
23449
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (test_zc_arg + 1 > argc)
23450 {
23451 printf("%d\n", argc);
23452 printf("expected -test-zc <path to test dir>\n");
23453 zq_exit(1);
23454 }
23455
23456 1 const char* test_dir = argv[test_zc_arg + 1];
23457
23458 // We need to init some stuff before loading a quest file will work.
23459 1 int fake_errno = 0;
23460 1 allegro_errno = &fake_errno;
23461 1 get_qst_buffers();
23462
23463 1 bool success = true;
23464
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!partial_load_test(test_dir))
23465 {
23466 success = false;
23467 printf("partial_load_test failed\n");
23468 }
23469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (success)
23470 1 printf("all tests passed\n");
23471 1 zq_exit(success ? 0 : 1);
23472 1 }
23473
23474 8 int unencrypt_qst_arg = used_switch(argc, argv, "-unencrypt-qst");
23475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (unencrypt_qst_arg > 0)
23476 {
23477 if (unencrypt_qst_arg + 3 > argc)
23478 {
23479 printf("%d\n", argc);
23480 printf("expected -unencrypt-qst <input> <output>\n");
23481 zq_exit(1);
23482 }
23483
23484 const char* input_filename = argv[unencrypt_qst_arg + 1];
23485 const char* output_filename = argv[unencrypt_qst_arg + 2];
23486 do_unencrypt_qst_command(input_filename, output_filename);
23487 zq_exit(0);
23488 }
23489
23490 8 int uncompress_qst_arg = used_switch(argc, argv, "-uncompress-qst");
23491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (uncompress_qst_arg > 0)
23492 {
23493 if (uncompress_qst_arg + 3 > argc)
23494 {
23495 printf("%d\n", argc);
23496 printf("expected -uncompress-qst <input> <output>\n");
23497 zq_exit(1);
23498 }
23499
23500 const char* input_filename = argv[uncompress_qst_arg + 1];
23501 const char* output_filename = argv[uncompress_qst_arg + 2];
23502 do_uncompress_qst_command(input_filename, output_filename);
23503 zq_exit(0);
23504 }
23505
23506 8 three_finger_flag=false;
23507
23508 #ifndef __EMSCRIPTEN__
23509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(zc_get_config("zquest","open_debug_console",0))
23510 initConsole();
23511 #endif
23512
23513 LOCK_VARIABLE(lastfps);
23514
23515 LOCK_VARIABLE(framecnt);
23516 LOCK_FUNCTION(fps_callback);
23517
23518
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
23519 {
23520 Z_error_fatal("couldn't allocate timer");
23521 }
23522
23523
23524 LOCK_VARIABLE(dclick_status);
23525 LOCK_VARIABLE(dclick_time);
23526 8 lock_dclick_function();
23527 8 install_int(dclick_check, 20);
23528
23529 8 set_gfx_mode(GFX_TEXT,80,50,0,0);
23530
23531 8 load_assets();
23532
23533 8 Z_message("OK\n");
23534
23535
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 helpstr = util::read_text_file("docs/zquest.txt");
23536
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 zstringshelpstr = util::read_text_file("docs/zstrings.txt");
23537
23538 // loading data files...
23539
23540 8 filepath[0]=temppath[0]=0;
23541
23542 8 const char *default_path="";
23543
23544 8 strcpy(datapath,zc_get_config("zquest",data_path_name,default_path));
23545 8 strcpy(midipath,zc_get_config("zquest",midi_path_name,default_path));
23546 8 strcpy(imagepath,zc_get_config("zquest",image_path_name,default_path));
23547 8 strcpy(tmusicpath,zc_get_config("zquest",tmusic_path_name,default_path));
23548 8 chop_path(datapath);
23549 8 chop_path(midipath);
23550 8 chop_path(imagepath);
23551 8 chop_path(tmusicpath);
23552
23553 8 DisableLPalShortcuts = zc_get_config("zquest","dis_lpal_shortcut",1);
23554 8 DisableCompileConsole = zc_get_config("zquest","internal_compile_console",0);
23555 8 MouseScroll = zc_get_config("zquest","mouse_scroll",0);
23556 8 MMapCursorStyle = zc_get_config("zquest","cursorblink_style",1);
23557 8 LayerDitherBG = zc_get_config("zquest", "layer_dither_bg", -1);
23558 8 LayerDitherSz = zc_get_config("zquest", "layer_dither_sz", 3);
23559 8 InvalidBG = zc_get_config("zquest", "invalid_bg", 0);
23560 8 TileProtection = zc_get_config("zquest","tile_protection",1);
23561 8 ComboProtection = zc_get_config("zquest","combo_protection",TileProtection);
23562 8 ShowGrid = zc_get_config("zquest","show_grid",0);
23563 8 ShowCurScreenOutline = zc_get_config("zquest","show_current_screen_outline",1);
23564 8 ShowScreenGrid = zc_get_config("zquest","show_screen_grid",0);
23565 8 ShowRegionGrid = zc_get_config("zquest","show_region_grid",1);
23566 8 GridColor = zc_get_config("zquest","grid_color",15);
23567 8 CmbCursorCol = zc_get_config("zquest","combo_cursor_color",15);
23568 8 TilePgCursorCol = zc_get_config("zquest","tpage_cursor_color",15);
23569 8 CmbPgCursorCol = zc_get_config("zquest","cpage_cursor_color",15);
23570 8 TTipHLCol = zc_get_config("zquest","ttip_hl_color",13);
23571 8 CheckerCol1 = zc_get_config("zquest","checker_color_1",7);
23572 8 CheckerCol2 = zc_get_config("zquest","checker_color_2",8);
23573 8 SnapshotFormat = zc_get_config("zquest","snapshot_format",3);
23574 8 SnapshotScale = zc_get_config("zquest","snapshot_scale",2);
23575 8 SavePaths = zc_get_config("zquest","save_paths",1);
23576 8 CycleOn = zc_get_config("zquest","cycle_on",1);
23577 8 ShowFPS = zc_get_config("zquest","showfps",0)!=0;
23578 8 SaveDragResize = zc_get_config("zquest","save_drag_resize",0)!=0;
23579 8 DragAspect = zc_get_config("zquest","drag_aspect",0)!=0;
23580 8 SaveWinPos = zc_get_config("zquest","save_window_position",0)!=0;
23581 8 ComboBrush = zc_get_config("zquest","combo_brush",0);
23582 8 FloatBrush = zc_get_config("zquest","float_brush",0);
23583 8 AutoBrush = zc_get_config("zquest","autobrush",1);
23584 8 LinkedScroll = zc_get_config("zquest","linked_comboscroll",0);
23585 8 allowHideMouse = zc_get_config("ZQ_GUI","allowHideMouse",0);
23586 8 ShowFavoriteComboModes = zc_get_config("ZQ_GUI","show_fav_combo_modes",1);
23587 8 NoHighlightLayer0 = zc_get_config("zquest","no_highlight_layer0",0);
23588 8 RulesetDialog = zc_get_config("zquest","rulesetdialog",1);
23589 8 EnableTooltips = zc_get_config("zquest","enable_tooltips",1);
23590 8 TooltipsHighlight = zc_get_config("zquest","ttip_highlight",1);
23591 8 tooltip_maxtimer = vbound(zc_get_config("zquest","ttip_timer",30),0,60*60);
23592 8 ShowFFScripts = zc_get_config("zquest","showffscripts",1);
23593 8 ShowSquares = zc_get_config("zquest","showsquares",1);
23594 8 ShowFFCs = zc_get_config("zquest","showffcs",0);
23595 8 ShowInfo = zc_get_config("zquest","showinfo",1);
23596 8 skipLayerWarning = zc_get_config("zquest","skip_layer_warning",0);
23597 8 numericalFlags = zc_get_config("zquest","numerical_flags",0);
23598 8 ViewLayer2BG = zc_get_config("zquest","layer2_bg",0);
23599 8 ViewLayer3BG = zc_get_config("zquest","layer3_bg",0);
23600 8 ActiveLayerHighlight = zc_get_config("zquest","hl_active_lyr",0);
23601 8 DragCenterOfSquares = zc_get_config("zquest","drag_squares_from_center",0);
23602
23603 8 OpenLastQuest = zc_get_config("zquest","open_last_quest",0);
23604 8 ShowMisalignments = zc_get_config("zquest","show_misalignments",0);
23605 8 AnimationOn = zc_get_config("zquest","animation_on",1);
23606 8 AutoBackupRetention = zc_get_config("zquest","auto_backup_retention",2);
23607 8 AutoSaveInterval = zc_get_config("zquest","auto_save_interval",6);
23608 8 AutoSaveRetention = zc_get_config("zquest","auto_save_retention",2);
23609 8 UncompressedAutoSaves = zc_get_config("zquest","uncompressed_auto_saves",1);
23610 8 OverwriteProtection = zc_get_config("zquest","overwrite_prevention",0)!=0;
23611 8 ImportMapBias = zc_get_config("zquest","import_map_bias",0);
23612
23613 8 KeyboardRepeatDelay = zc_get_config("zquest","keyboard_repeat_delay",300);
23614 8 KeyboardRepeatRate = zc_get_config("zquest","keyboard_repeat_rate",80);
23615
23616 // Frameskip = zc_get_config("zquest","frameskip",0); //todo: this is not actually supported yet.
23617 8 RequestedFPS = zc_get_config("zquest","fps",60);
23618
23619 // Autofill for Combo Page, Tile Page
23620 8 PreFillTileEditorPage = zc_get_config("zquest","PreFillTileEditorPage",0);
23621 8 PreFillComboEditorPage = zc_get_config("zquest","PreFillComboEditorPage",0);
23622
23623 8 pixeldb = zc_get_config("ZQ_GUI","bottom_8_pixels",0);
23624 8 infobg = zc_get_config("ZQ_GUI","info_text_bg",0);
23625
23626 8 large_merged_combopane = zc_get_config("ZQ_GUI","merge_cpane_large",0);
23627 8 compact_merged_combopane = zc_get_config("ZQ_GUI","merge_cpane_compact",1);
23628
23629 8 compact_square_panels = zc_get_config("ZQ_GUI","square_panels_compact",0);
23630
23631 8 large_zoomed_fav = zc_get_config("ZQ_GUI","zoom_fav_large",0);
23632 8 compact_zoomed_fav = zc_get_config("ZQ_GUI","zoom_fav_compact",1);
23633 8 large_zoomed_cmd = zc_get_config("ZQ_GUI","zoom_cmd_large",1);
23634 8 compact_zoomed_cmd = zc_get_config("ZQ_GUI","zoom_cmd_compact",1);
23635
23636
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(zc_get_config("gui","disable_window_resizing",0))
23637 all_set_resize_flag(false);
23638
23639 8 load_hotkeys();
23640
23641 #ifdef _WIN32
23642 zqUseWin32Proc = zc_get_config("zquest","zq_win_proc_fix",0);
23643
23644 #endif
23645
23646
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!render_timer_start())
23647 {
23648 Z_error_fatal("couldn't allocate timer");
23649 }
23650
23651 8 byte layermask = zc_get_config("zquest","layer_mask",0x7F);
23652 8 int32_t usefullscreen = zc_get_config("zquest","fullscreen",0);
23653 8 tempmode = (usefullscreen == 0 ? GFX_AUTODETECT_WINDOWED : GFX_AUTODETECT_FULLSCREEN);
23654
23655
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 8 times.
64 for(int32_t x=0; x<7; x++)
23656 {
23657 56 LayerMaskInt[x]=get_bit(&layermask,x);
23658 56 }
23659
23660 8 DuplicateAction[0] = zc_get_config("zquest","normal_duplicate_action",2);
23661 8 DuplicateAction[1] = zc_get_config("zquest","horizontal_duplicate_action",0);
23662 8 DuplicateAction[2] = zc_get_config("zquest","vertical_duplicate_action",0);
23663 8 DuplicateAction[3] = zc_get_config("zquest","both_duplicate_action",0);
23664 8 LeechUpdate = zc_get_config("zquest","leech_update",500);
23665 8 LeechUpdateTiles = zc_get_config("zquest","leech_update_tiles",1);
23666 8 OnlyCheckNewTilesForDuplicates = zc_get_config("zquest","only_check_new_tiles_for_duplicates",0);
23667 //gui_colorset = zc_get_config("zquest","gui_colorset",0);
23668
23669 8 strcpy(last_timed_save,zc_get_config("zquest","last_timed_save",""));
23670
23671 8 midi_volume = zc_get_config("zquest", "midi", 255);
23672
23673 8 abc_patternmatch = zc_get_config("zquest", "lister_pattern_matching", 1);
23674 8 NoScreenPreview = zc_get_config("zquest", "no_preview", 0);
23675
23676 8 monochrome_console = zc_get_config("CONSOLE","monochrome_debuggers",0)?1:0;
23677
23678 8 try_recovering_missing_scripts = 0;//zc_get_config("Compiler", "try_recovering_missing_scripts",0);
23679 //We need to remove all of the zeldadx refs to the config file for zquest.
23680
23681 8 set_keyboard_rate(KeyboardRepeatDelay,KeyboardRepeatRate);
23682
23683 8 is_compact = zc_get_config("ZQ_GUI","compact_mode",1);
23684 8 mapscreenbmp = nullptr;
23685 8 brushbmp = nullptr;
23686 8 brushscreen = nullptr;
23687 8 screen2 = nullptr;
23688 8 tmp_scr = nullptr;
23689 8 menu1 = nullptr;
23690 8 menu3 = nullptr;
23691
23692
2/2
✓ Branch 0 taken 10080 times.
✓ Branch 1 taken 8 times.
10088 for(int32_t i=0; i<MAXFAVORITECOMBOS; ++i)
23693 {
23694 10080 favorite_combos[i]=-1;
23695 10080 pool_combos[i].clear();
23696 10080 }
23697 8 FavoriteComboPage = 0;
23698 8 pool_dirty = true;
23699
23700
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(used_switch(argc,argv,"-d"))
23701 {
23702 set_debug(!strcmp(zquestpwd,zc_get_config("zquest","debug_this","")));
23703 }
23704
23705 8 zcmusic_init();
23706 8 zcmixer = zcmixer_create();
23707 1121 install_int_ex([](){ zcmusic_poll(); }, MSEC_TO_TIMER(25));
23708
23709 8 set_color_depth(8);
23710
23711 8 set_close_button_callback((void (*)()) hit_close_button);
23712
23713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(used_switch(argc,argv,"-fullscreen"))
23714 {
23715 tempmode = GFX_AUTODETECT_FULLSCREEN;
23716 }
23717
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 else if(used_switch(argc,argv,"-windowed"))
23718 {
23719 tempmode=GFX_AUTODETECT_WINDOWED;
23720 }
23721
23722 8 zq_screen_w = LARGE_W;
23723 8 zq_screen_h = LARGE_H;
23724 8 window_width = zc_get_config("zquest","window_width",-1);
23725 8 window_height = zc_get_config("zquest","window_height",-1);
23726 8 auto [w, h] = zc_get_default_display_size(LARGE_W, LARGE_H, window_width, window_height);
23727
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 int32_t videofail = is_headless() ? 0 : (set_gfx_mode(tempmode,w,h,zq_screen_w,zq_screen_h));
23728
23729 //extra block here is intentional
23730
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(videofail!=0)
23731 {
23732 quit_game();
23733 allegro_exit();
23734 }
23735
23736 8 zalleg_create_window();
23737 8 Z_message("gfx mode set at -%d %dbpp %d x %d \n",
23738 8 tempmode, get_color_depth(), zq_screen_w, zq_screen_h);
23739
23740 8 set_window_title("ZC Editor");
23741
23742 8 load_size_poses();
23743
23744
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!is_headless())
23745 {
23746 // Just in case.
23747 while (!all_get_display()) {
23748 al_rest(1);
23749 }
23750
23751 al_resize_display(all_get_display(), w, h);
23752 }
23753
23754
23755 #ifndef __EMSCRIPTEN__
23756
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 if (!all_get_fullscreen_flag() && !is_headless()) {
23757 al_resize_display(all_get_display(), w, h);
23758
23759 int window_w = al_get_display_width(all_get_display());
23760 int window_h = al_get_display_height(all_get_display());
23761
23762 int new_x = zc_get_config("zquest","window_x",0);
23763 int new_y = zc_get_config("zquest","window_y",0);
23764 if(zc_get_config("zquest","save_window_position",0) && (new_x || new_y))
23765 {
23766 //load saved position
23767 //already stored in new_x/new_y
23768 }
23769 else
23770 {
23771 //Get default position
23772 ALLEGRO_MONITOR_INFO info;
23773 al_get_monitor_info(0, &info);
23774
23775 int mw = (info.x2 - info.x1);
23776 int mh = (info.y2 - info.y1);
23777 new_x = mw / 2 - window_w / 2;
23778 new_y = mh / 2 - window_h / 2;
23779 //Don't spawn the window too far down (taskbar?)
23780 if(new_y + window_h > mh - 72)
23781 new_y = mh-72-window_h;
23782 }
23783 #ifdef ALLEGRO_MACOSX
23784 if (zc_get_config("zquest","save_window_position",0))
23785 al_set_window_position(all_get_display(), new_x, new_y);
23786 #else
23787 al_set_window_position(all_get_display(), new_x, new_y);
23788 #endif
23789 }
23790 #endif
23791
23792 8 position_mouse(zq_screen_w/2,zq_screen_h/2);
23793
23794 8 dmapbmp_small = create_bitmap_ex(8,65,33);
23795 8 dmapbmp_large = create_bitmap_ex(8,177,81);
23796
23797
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!screen2 || !tmp_scr || !menu1 || !menu3 || !dmapbmp_large || !dmapbmp_large || !brushbmp || !brushscreen)// || !brushshadowbmp )
23798 {
23799 Z_error_fatal("Failed to create system bitmaps!\n");
23800 return 1;
23801 }
23802
23803 8 int quick_assign_arg = used_switch(argc, argv, "-quick-assign");
23804
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (quick_assign_arg > 0)
23805 {
23806 6 is_zq_replay_test = true;
23807 6 set_headless_mode();
23808
23809 6 int load_ret = load_quest(argv[quick_assign_arg + 1], false);
23810 6 bool success = load_ret == qe_OK;
23811
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!success)
23812 {
23813 printf("Failed to load quest: %d\n", load_ret);
23814 zq_exit(1);
23815 }
23816
23817 6 success = do_compile_and_slots(1, false);
23818
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!success)
23819 {
23820 printf("Failed to compile\n");
23821 zq_exit(1);
23822 }
23823
23824 6 success = save_quest(argv[quick_assign_arg + 1], false) == 0;
23825
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!success)
23826 {
23827 printf("Failed to save quest\n");
23828 zq_exit(1);
23829 }
23830
23831 6 zq_exit(0);
23832 6 }
23833
23834 8 int smart_assign_arg = used_switch(argc, argv, "-smart-assign");
23835
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (smart_assign_arg > 0)
23836 {
23837 is_zq_replay_test = true;
23838 set_headless_mode();
23839
23840 int load_ret = load_quest(argv[smart_assign_arg + 1], false);
23841 bool success = load_ret == qe_OK;
23842 if (!success)
23843 {
23844 printf("Failed to load quest: %d\n", load_ret);
23845 zq_exit(1);
23846 }
23847
23848 success = do_compile_and_slots(2, false);
23849 if (!success)
23850 {
23851 printf("Failed to compile\n");
23852 zq_exit(1);
23853 }
23854
23855 success = save_quest(argv[smart_assign_arg + 1], false) == 0;
23856 if (!success)
23857 {
23858 printf("Failed to save quest\n");
23859 zq_exit(1);
23860 }
23861
23862 zq_exit(0);
23863 }
23864
23865 8 int export_strings_arg = used_switch(argc, argv, "-export-strings");
23866
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (export_strings_arg > 0)
23867 {
23868
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (export_strings_arg + 3 > argc)
23869 {
23870 printf("%d\n", argc);
23871 printf("expected -export-strings input.qst output.tsv\n");
23872 zq_exit(1);
23873 }
23874
23875 1 is_zq_replay_test = true;
23876 1 set_headless_mode();
23877
23878 1 int load_ret = load_quest(argv[export_strings_arg + 1], false);
23879 1 bool success = load_ret == qe_OK;
23880
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!success)
23881 {
23882 printf("Failed to load quest: %d\n", load_ret);
23883 zq_exit(1);
23884 }
23885
23886 1 success = save_strings_tsv(argv[export_strings_arg + 2]);
23887
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!success)
23888 {
23889 printf("Failed to export strings\n");
23890 zq_exit(1);
23891 }
23892
23893 1 zq_exit(0);
23894 1 }
23895
23896
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!is_headless())
23897 {
23898 zc_set_palette(asset_pal);
23899 get_palette(RAMpal);
23900 load_colorset(gui_colorset);
23901 zc_set_palette(RAMpal);
23902 clear_to_color(screen,vc(0));
23903 }
23904
23905 8 zScript = string();
23906 8 strcpy(zScriptBytes, "0 Bytes in Buffer");
23907
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
20 for(int32_t i=0; i<MOUSE_BMP_MAX; i++)
23908 {
23909
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t j=0; j<4; j++)
23910 {
23911 48 mouse_bmp[i][j] = NULL;
23912 48 mouse_bmp_1x[i][j] = NULL;
23913 48 }
23914 12 }
23915 8 load_mice();
23916 8 gui_mouse_focus=0;
23917 8 MouseSprite::set(ZQM_NORMAL);
23918 8 render_zq(); // Ensure the rendering bitmaps are setup.
23919
23920 #ifdef __EMSCRIPTEN__
23921 em_mark_ready_status();
23922 #endif
23923
23924 8 load_icons();
23925
23926 8 bool load_last_timed_save=false;
23927
23928 8 load_recent_quests();
23929 8 refresh_recent_menu();
23930 //clearConsole();
23931
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8 if((last_timed_save[0]!=0)&&(exists(last_timed_save)))
23932 {
23933 if(jwin_alert("ZQuest","It appears that ZQuest crashed last time.","Would you like to load the last timed save?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
23934 {
23935 int32_t ret = load_quest(last_timed_save);
23936
23937 if(ret == qe_OK)
23938 {
23939 strcpy(filepath,last_timed_save);
23940 load_last_timed_save=true;
23941 saved=false;
23942 }
23943 else
23944 {
23945 jwin_alert("Error","Unable to reload the last timed save.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
23946 }
23947 }
23948 }
23949
23950
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if(!load_last_timed_save)
23951 {
23952 1 strcpy(filepath,zc_get_config("zquest",last_quest_name,""));
23953
23954
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if(argc>1 && argv[1][0]!='-')
23955 {
23956 int32_t ret = load_quest(argv[1]);
23957
23958 if(ret == qe_OK)
23959 {
23960 first_save=true;
23961 strcpy(filepath,argv[1]);
23962 refresh(rALL);
23963 }
23964 }
23965
2/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 else if(OpenLastQuest&&filepath[0]&&exists(filepath)&&!used_switch(argc,argv,"-new"))
23966 {
23967 int32_t ret = load_quest(filepath);
23968
23969 if(ret == qe_OK)
23970 {
23971 first_save=true;
23972 refresh(rALL);
23973 }
23974 else
23975 {
23976 filepath[0]=temppath[0]=0;
23977 first_save=false;
23978 }
23979 }
23980 else
23981 {
23982
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (onNew() == D_CLOSE)
23983 {
23984 1 Z_message("User canceled creating new quest, closing.\n");
23985 1 exit(0);
23986 }
23987
23988 //otherwise the blank quest gets the name of the last loaded quest... not good! -DD
23989 filepath[0]=temppath[0]=0;
23990 first_save=false;
23991 }
23992 }
23993
23994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if(used_switch(argc,argv,"-q"))
23995 {
23996 Z_message("-q switch used, quitting program.\n");
23997 zq_exit(0);
23998 }
23999
24000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int32_t x=0; x<MAXITEMS; x++)
24001 {
24002 lens_hint_item[x][0]=0;
24003 lens_hint_item[x][1]=0;
24004 }
24005
24006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int32_t x=0; x<MAXWPNS; x++)
24007 {
24008 lens_hint_weapon[x][0]=0;
24009 lens_hint_weapon[x][1]=0;
24010 }
24011
24012 7 load_selections();
24013 7 load_arrows();
24014 7 clear_to_color(menu1,vc(0));
24015 7 DIALOG_PLAYER *player2=init_dialog(dialogs,-1);
24016
24017 7 get_palette(RAMpal);
24018
24019 7 rgb_map = &zq_rgb_table;
24020
24021 #ifdef __EMSCRIPTEN__
24022 {
24023 int qs_map = EM_ASM_INT({
24024 return new URL(location.href).searchParams.get('map') ?? -1;
24025 });
24026 int qs_screen = EM_ASM_INT({
24027 return new URL(location.href).searchParams.get('screen') ?? -1;
24028 });
24029 if (qs_map != -1 && qs_screen != -1) {
24030 Map.setCurrMap(qs_map);
24031 Map.setCurrScr(qs_screen);
24032 }
24033 }
24034 #endif
24035
24036 // setup_combo_animations();
24037 7 pause_refresh = false;
24038 7 refresh_pal();
24039 7 refresh(rALL);
24040
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int q = 0; q < brush_width_menu.size(); ++q)
24041 brush_width_menu.at(q)->select(q==0);
24042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int q = 0; q < brush_height_menu.size(); ++q)
24043 brush_height_menu.at(q)->select(q==0);
24044 7 set_filltype(1);
24045
24046 7 rebuild_trans_table();
24047
24048
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (!is_headless())
24049 {
24050 set_display_switch_mode(SWITCH_BACKGROUND);
24051 set_display_switch_callback(SWITCH_OUT, switch_out);
24052 set_display_switch_callback(SWITCH_IN, switch_in);
24053 }
24054
24055
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!update_dialog(player2))
24056 exiting_program = true;
24057 //clear_keybuf();
24058 7 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
24059 7 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
24060
24061 7 fix_drawing_mode_menu();
24062
24063
24064 #ifdef _WIN32
24065
24066 if(zqUseWin32Proc != FALSE)
24067 {
24068 al_trace("Config file warning: \"zq_win_proc_fix\" enabled switch found. This can cause crashes on some computers.\n");
24069 win32data.zqSetDefaultThreadPriority(0);
24070 win32data.zqSetCustomCallbackProc(al_get_win_window_handle(all_get_display()));
24071 }
24072
24073 #endif
24074
24075 7 time(&auto_save_time_start);
24076
24077 7 FFCore.init();
24078 7 ZQincludePaths = FFCore.includePaths;
24079
24080 7 Map.setCopyFFC(-1); //Do not have an initial ffc on the clipboard.
24081 7 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
24082 7 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
24083 7 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
24084 7 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
24085 7 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
24086
24087 7 call_foo_dlg();
24088
24089 7 application_has_loaded = true;
24090
24091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 while(!exiting_program)
24092 {
24093 handle_sentry_tags();
24094
24095 #ifdef _WIN32
24096 if(zqUseWin32Proc != FALSE)
24097 win32data.Update(Frameskip); //experimental win32 fixes
24098 #endif
24099 check_autosave();
24100 ++alignment_arrow_timer;
24101
24102 if(alignment_arrow_timer>63)
24103 {
24104 alignment_arrow_timer=0;
24105 }
24106 ++frame;
24107
24108 file_menu.disable_uid(MENUID_FILE_SAVE, saved||disable_saving||OverwriteProtection);
24109 file_menu.disable_uid(MENUID_FILE_REVERT, saved||disable_saving||OverwriteProtection);
24110 file_menu.disable_uid(MENUID_FILE_SAVEAS, disable_saving);
24111
24112 fixtools_menu.disable_uid(MENUID_FIXTOOL_OLDSTRING,
24113 !(get_qr(qr_OLD_STRING_EDITOR_MARGINS)
24114 ||get_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT)));
24115
24116 edit_menu.disable_uid(MENUID_EDIT_UNDO, !Map.CanUndo());
24117 edit_menu.disable_uid(MENUID_EDIT_REDO, !Map.CanRedo());
24118
24119 bool canpaste = Map.CanPaste();
24120 edit_menu.disable_uid(MENUID_EDIT_PASTE, !canpaste);
24121 edit_menu.disable_uid(MENUID_EDIT_PASTEALL, !canpaste);
24122 edit_menu.disable_uid(MENUID_EDIT_ADVPASTE, !canpaste);
24123 edit_menu.disable_uid(MENUID_EDIT_SPECPASTE, !canpaste);
24124 rc_menu_screen.disable_uid(MENUID_RCSCREEN_PASTE, !canpaste);
24125 rc_menu_screen.disable_uid(MENUID_RCSCREEN_ADVPASTE, !canpaste);
24126 rc_menu_screen.disable_uid(MENUID_RCSCREEN_SPECPASTE, !canpaste);
24127 for(MenuItem& mit : paste_menu.inner())
24128 mit.disable(!canpaste);
24129 for(MenuItem& mit : paste_item_menu.inner())
24130 mit.disable(!canpaste);
24131
24132 edit_menu.disable_uid(MENUID_EDIT_COPY, !(Map.CurrScr()->valid&mVALID));
24133 edit_menu.disable_uid(MENUID_EDIT_DELETE, !(Map.CurrScr()->valid&mVALID));
24134
24135 // Are some things selected?
24136 view_menu.select_uid(MENUID_VIEW_WALKABILITY, Flags&cWALK);
24137 view_menu.select_uid(MENUID_VIEW_FLAGS, Flags&cFLAGS);
24138 view_menu.select_uid(MENUID_VIEW_CSET, Flags&cCSET);
24139 view_menu.select_uid(MENUID_VIEW_TYPES, Flags&cCTYPE);
24140 view_menu.select_uid(MENUID_VIEW_INFO, ShowInfo);
24141 view_menu.select_uid(MENUID_VIEW_SQUARES, ShowSquares);
24142 view_menu.select_uid(MENUID_VIEW_FFCS, ShowFFCs);
24143 view_menu.select_uid(MENUID_VIEW_SCRIPTNAMES, ShowFFScripts);
24144 view_menu.select_uid(MENUID_VIEW_GRID, ShowGrid);
24145 view_menu.select_uid(MENUID_VIEW_SCREENGRID, ShowScreenGrid);
24146 view_menu.select_uid(MENUID_VIEW_REGIONGRID, ShowRegionGrid);
24147 view_menu.select_uid(MENUID_VIEW_CURSCROUTLINE, ShowCurScreenOutline);
24148 view_menu.select_uid(MENUID_VIEW_DARKNESS, get_qr(qr_NEW_DARKROOM) && (Flags&cNEWDARK));
24149 view_menu.select_uid(MENUID_VIEW_L2BG, ViewLayer2BG);
24150 view_menu.select_uid(MENUID_VIEW_L3BG, ViewLayer3BG);
24151 view_menu.select_uid(MENUID_VIEW_LAYERHIGHLIGHT, ActiveLayerHighlight);
24152
24153 maps_menu.disable_uid(MENUID_MAPS_NEXT, !map_count || Map.getCurrMap() >= map_count);
24154 maps_menu.disable_uid(MENUID_MAPS_PREV, Map.getCurrMap()<=0);
24155
24156 etc_menu.disable_uid(MENUID_ETC_VIDMODE, isFullScreen()==1);
24157 etc_menu.select_uid(MENUID_ETC_FULLSCREEN, isFullScreen()==1);
24158
24159 if(!update_dialog(player2))
24160 exiting_program = true;
24161
24162 //clear_keybuf();
24163 handle_close_btn_quit();
24164 }
24165
24166 7 zq_exit(0);
24167 7 return 0;
24168 }
24169 END_OF_MAIN()
24170
24171 11 void zq_exit(int code)
24172 {
24173 11 set_is_exiting();
24174 11 parser_console.kill();
24175 11 killConsole();
24176
24177 11 quit_game();
24178 11 allegro_exit();
24179 11 exit(code);
24180 }
24181
24182 56 void init_bitmap(BITMAP** bmp, int32_t w, int32_t h)
24183 {
24184
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if(*bmp)
24185 destroy_bitmap(*bmp);
24186 56 *bmp = create_bitmap_ex(8,w,h);
24187 56 clear_bitmap(*bmp);
24188 56 }
24189 8 void load_size_poses()
24190 {
24191 8 ttip_uninstall_all();
24192
24193 8 FONT* favcmdfont = get_custom_font(CFONT_FAVCMD);
24194 8 FONT* guifont = get_custom_font(CFONT_GUI);
24195
24196 8 d_nbmenu_proc(MSG_START, &dialogs[0], 0);
24197
24198 8 commands_list.xscale = command_buttonwidth;
24199 8 commands_list.yscale = 10+text_height(favcmdfont);
24200
24201 8 auto drawmode_wid = 64;
24202
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 8 times.
56 for(auto q = 0; q < dm_max; ++q)
24203 {
24204 48 auto wid = text_length(guifont, dm_names[q]);
24205
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(wid > drawmode_wid)
24206 drawmode_wid = wid;
24207 48 }
24208
24209 //Main GUI objects
24210
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(is_compact)
24211 {
24212 8 num_combo_cols = 2;
24213 8 combo_col_scale = 16;
24214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(compact_merged_combopane)
24215 {
24216 8 num_combo_cols = 1;
24217 8 combo_col_scale = 32;
24218 8 }
24219
24220 8 mapscreen_x=0;
24221 8 mapscreen_y=dialogs[0].h;
24222 8 mapscreen_screenunit_scale=3;
24223 8 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
24224 8 showedges=0;
24225 8 showallpanels=0;
24226
24227 8 blackout_color=8;
24228
24229 8 auto mapscr_wid = (((showedges?2:0)+16)*16*mapscreen_screenunit_scale);
24230 8 combolist_window.w=zq_screen_w-mapscr_wid;
24231 8 combolist_window.x=zq_screen_w-combolist_window.w;
24232
24233 8 favorites_window.x=combolist_window.x;
24234 8 favorites_window.w=combolist_window.w;
24235 8 favorites_window.h=136;
24236 8 favorites_window.y=zq_screen_h-favorites_window.h;
24237
24238 8 combolist_window.y=0;
24239 8 combolist_window.h=favorites_window.y-combolist_window.y;
24240
24241 8 combo_preview.x=zq_screen_w-32-8;
24242 8 combo_preview.y=combolist_window.y+6;
24243 8 combo_preview.w=32;
24244 8 combo_preview.h=32;
24245 8 combo_preview2.clear();
24246
24247 8 auto col_wid = 4*combo_col_scale;
24248 8 auto cols_wid = col_wid * num_combo_cols;
24249 8 auto cols_spacing = (combolist_window.w-cols_wid)/(num_combo_cols+1);
24250
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 for(auto q = 0; q < num_combo_cols; ++q)
24251 {
24252 8 combolist[q].x=combolist_window.x+(cols_spacing*(q+1))+(col_wid*q);
24253 8 combolist[q].y=combolist_window.y+54;
24254 8 combolist[q].w=4;
24255 8 combolist[q].h=compact_merged_combopane ? 15 : 30;
24256 8 combolist[q].xscale = combo_col_scale;
24257 8 combolist[q].yscale = combo_col_scale;
24258
24259 8 comboaliaslist[q].x = combolist[q].x;
24260 8 comboaliaslist[q].y = combolist[q].y;
24261 8 comboaliaslist[q].w = 4;
24262 8 comboaliaslist[q].h = compact_merged_combopane ? 13 : 26;
24263 8 comboaliaslist[q].xscale = combo_col_scale;
24264 8 comboaliaslist[q].yscale = combo_col_scale;
24265
24266 8 combolistscrollers[q].w=2;
24267 8 combolistscrollers[q].h=1;
24268 8 combolistscrollers[q].xscale=11;
24269 8 combolistscrollers[q].yscale=11;
24270 8 combolistscrollers[q].x=combolist[q].x+(combolist[q].w*combolist[q].xscale/2)-11;
24271 8 combolistscrollers[q].y=combolist[q].y-combolistscrollers[q].th()-3;
24272 8 }
24273
24274 8 comboalias_preview.x=zq_screen_w-((combolist_window.w+64)/2);
24275 8 comboalias_preview.h=64;
24276 8 comboalias_preview.y=favorites_window.y-comboalias_preview.h-8;
24277 8 comboalias_preview.w=64;
24278
24279 8 combo_merge_btn.w = 20;
24280 8 combo_merge_btn.h = 20;
24281 8 combo_merge_btn.x = zq_screen_w-(combolist_window.w+combo_merge_btn.w)/2;
24282 8 combo_merge_btn.y = combolist[0].y-combo_merge_btn.h;
24283
24284
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(num_combo_cols == 1)
24285 {
24286 8 combolistscrollers[0].x += 34;
24287 8 }
24288 8 drawmode_btn.x = combolist_window.x-drawmode_wid;
24289 8 drawmode_btn.y = 0;
24290 8 drawmode_btn.w = drawmode_wid;
24291 8 drawmode_btn.h = mapscreen_y;
24292
24293 8 compactbtn.w = text_length(guifont,"> Compact")+10;
24294 8 compactbtn.x = drawmode_btn.x-compactbtn.w;
24295 8 compactbtn.y = drawmode_btn.y;
24296 8 compactbtn.h = drawmode_btn.h;
24297
24298 8 zoominbtn.w = text_length(guifont,"+")+10;
24299 8 zoominbtn.x = compactbtn.x-zoominbtn.w;
24300 8 zoominbtn.y = compactbtn.y;
24301 8 zoominbtn.h = compactbtn.h;
24302
24303 8 zoomoutbtn.w = text_length(guifont,"-")+10;
24304 8 zoomoutbtn.x = zoominbtn.x-zoomoutbtn.w;
24305 8 zoomoutbtn.y = compactbtn.y;
24306 8 zoomoutbtn.h = compactbtn.h;
24307
24308
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 8 times.
80 for(int32_t i=0; i<=8; i++)
24309 {
24310 72 map_page_bar[i].w = 48;
24311 72 map_page_bar[i].x = mapscreen_x+(i*48);
24312 72 map_page_bar[i].y = mapscreen_y+(11*16*mapscreen_screenunit_scale);
24313 72 map_page_bar[i].h = text_height(guifont)+12;
24314 72 }
24315
24316 8 minimap.w=7+48*3;
24317 8 minimap.h=16+27*3;
24318
24319 8 layer_panel.x=map_page_bar[6].x;
24320 8 layer_panel.y=map_page_bar[0].y;
24321 8 layer_panel.w=combolist_window.x - layer_panel.x;
24322 8 layer_panel.h=map_page_bar[0].h;
24323 8 layerpanel_buttonwidth = 51;
24324 8 layerpanel_buttonheight = layer_panel.h;
24325 8 layerpanel_checkbox_hei = layerpanel_buttonheight-4;
24326 8 layerpanel_checkbox_wid = 15;
24327
24328 8 minimap.x=3;
24329 8 minimap.y=layer_panel.y+layer_panel.h+4;
24330
24331 8 real_minimap.x = minimap.x+3;
24332 8 real_minimap.y = minimap.y+5;
24333 8 real_minimap.w = 16;
24334 8 real_minimap.h = 9;
24335 8 real_minimap.xscale = 9;
24336 8 real_minimap.yscale = 9;
24337 8 real_minimap.fw = real_minimap.xscale*8;
24338 8 real_minimap.fh = real_minimap.yscale*8;
24339
24340 8 int upscale_mm = 3;
24341 8 int xwid = real_minimap.tw()*(upscale_mm-1);
24342 8 int xhei = real_minimap.th()*(upscale_mm-1);
24343 8 minimap_zoomed.set(minimap.x, minimap.y-xhei, minimap.w+xwid, minimap.h+xhei+4);
24344 8 real_minimap_zoomed.set(minimap_zoomed.x+3, minimap_zoomed.y+5, real_minimap.w, real_minimap.h, real_minimap.xscale*upscale_mm, real_minimap.yscale*upscale_mm);
24345 8 real_minimap_zoomed.fw = real_minimap_zoomed.xscale*8;
24346 8 real_minimap_zoomed.fh = real_minimap_zoomed.yscale*8;
24347
24348 8 screrrorpos.x = combolist_window.x - 3;
24349 8 screrrorpos.y = layer_panel.y - 16;
24350
24351 8 mouse_scroll_h=10;
24352
24353 8 favorites_list.x=favorites_window.x+8;
24354 8 favorites_list.y=favorites_window.y+16;
24355 8 favorites_list.xscale = 16;
24356 8 favorites_list.yscale = 16;
24357 8 favorites_list.w=(favorites_window.w-16)/favorites_list.xscale;
24358 8 favorites_list.h=(favorites_window.h-24)/favorites_list.yscale;
24359
24360 8 commands_list.w=4;
24361
24362 8 int bh = commands_list.yscale;
24363 8 int bw = 26;
24364 8 commands_window.w=commands_list.w*commands_list.xscale+10+bw;
24365 8 commands_window.x=combolist_window.x-commands_window.w;
24366 8 commands_window.y=layer_panel.y+layer_panel.h;
24367 8 commands_window.h=zq_screen_h-commands_window.y;
24368 8 int bx = commands_window.x+2;
24369
24370 8 commands_list.y=commands_window.y+4;
24371 8 commands_list.h=(zq_screen_h - commands_list.y) / commands_list.yscale;
24372 8 commands_list.x=bx+bw;
24373
24374 8 commands_zoombtn.w = bw;
24375 8 commands_zoombtn.h = bh;
24376 8 commands_zoombtn.x = bx;
24377 8 commands_zoombtn.y = commands_list.y;
24378
24379 8 commands_infobtn.w = bw;
24380 8 commands_infobtn.h = bh;
24381 8 commands_infobtn.x = bx;
24382 8 commands_infobtn.y = commands_zoombtn.y + commands_infobtn.h;
24383
24384 8 commands_x.w = bw;
24385 8 commands_x.h = bh;
24386 8 commands_x.x = bx;
24387 8 commands_x.y = commands_infobtn.y + commands_x.h;
24388
24389 8 commands_txt.clear();
24390
24391 8 main_panel.x = 0;
24392 8 main_panel.y = layer_panel.y+layer_panel.h;
24393 8 main_panel.w = commands_window.x - main_panel.x;
24394 8 main_panel.h = 76+32;
24395 8 preview_panel = main_panel;
24396 8 preview_panel.x = 0;
24397 8 preview_panel.w = commands_window.x - preview_panel.x;
24398
24399 8 preview_text.x = preview_panel.x+3;
24400 8 preview_text.y = preview_panel.y+3;
24401 8 preview_text.w = 2;
24402 8 preview_text.h = 6;
24403 8 preview_text.xscale = 10;
24404 8 preview_text.yscale = text_height(get_zc_font(font_lfont_l));
24405
24406 8 panel_align = 1;
24407 8 int swapbtnw = 32, swapbtnh = 20;
24408 8 int swapbtnx = main_panel.x+main_panel.tw()-swapbtnw;
24409 8 squarepanel_swap_btn.set(swapbtnx, zq_screen_h-swapbtnh, swapbtnw, swapbtnh);
24410
24411 8 int sqx = minimap.x+minimap.tw();
24412 8 squares_panel.set(sqx,main_panel.y,main_panel.tw()-sqx,main_panel.th());
24413
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(compact_square_panels)
24414 {
24415 int cmpy = main_panel.y+(main_panel.th()/2);
24416 squarepanel_up_btn.set(swapbtnx, cmpy-swapbtnh, swapbtnw, swapbtnh);
24417 squarepanel_down_btn.set(swapbtnx, cmpy, swapbtnw, swapbtnh);
24418
24419 txtoffs_single.x = 18;
24420 txtoffs_single.y = 36;
24421 txtoffs_double_1.x = 18;
24422 txtoffs_double_1.y = 36;
24423 txtoffs_double_2.x = 18;
24424 txtoffs_double_2.y = 36 + text_height(get_custom_font(CFONT_GUI));
24425
24426 //Clear them all- if they stay cleared, they are invisible.
24427 itemsqr_pos.clear();
24428 stairsqr_pos.clear();
24429 warparrival_pos.clear();
24430 flagsqr_pos.clear();
24431 enemy_prev_pos.clear();
24432 for(int q = 0; q < 4; ++q)
24433 warpret_pos[q].clear();
24434
24435 int sqr_x1 = sqx+12;
24436 int sqr_y1 = main_panel.y+12;
24437 int sqr_xoffs = (16*2)+4 + 12;
24438 switch(compact_active_panel)
24439 {
24440 case 0: //Warp Squares
24441 {
24442 int x = sqr_x1;
24443 for(int q = 0; q < 4; ++q)
24444 {
24445 warpret_pos[q].set(x,sqr_y1,(16*2)+4,(16*2)+4);
24446 x += sqr_xoffs;
24447 }
24448 break;
24449 }
24450 case 1: //Other Squares
24451 {
24452 itemsqr_pos.set(sqr_x1+(sqr_xoffs*0), sqr_y1, (16*2)+4,(16*2)+4);
24453 stairsqr_pos.set(sqr_x1+(sqr_xoffs*1), sqr_y1, (16*2)+4,(16*2)+4);
24454 warparrival_pos.set(sqr_x1+(sqr_xoffs*2), sqr_y1, (16*2)+4,(16*2)+4);
24455 flagsqr_pos.set(sqr_x1+(sqr_xoffs*3), sqr_y1, (16*2)+4,(16*2)+4);
24456 break;
24457 }
24458 case 2: //Enemy Preview
24459 {
24460 enemy_prev_pos.set(sqr_x1, sqr_y1, 5, 2, 32, 32);
24461 break;
24462 }
24463 }
24464 }
24465 else
24466 {
24467 8 squarepanel_up_btn.clear();
24468 8 squarepanel_down_btn.clear();
24469 8 txtoffs_single.x = 10;
24470 8 txtoffs_single.y = 22;
24471 8 txtoffs_double_1.x = 10;
24472 8 txtoffs_double_1.y = 22;
24473 8 txtoffs_double_2.x = 10;
24474 8 txtoffs_double_2.y = 30;
24475
24476
24477 8 int sqr_x1 = sqx+24;
24478 8 int sqr_y1 = main_panel.y+12;
24479 8 int sqr_y2 = sqr_y1+42;
24480 8 int sqr_xdist = 32;
24481 8 itemsqr_pos.set(sqr_x1+(sqr_xdist*0),sqr_y1,20,20);
24482 8 stairsqr_pos.set(sqr_x1+(sqr_xdist*1),sqr_y1,20,20);
24483 8 warparrival_pos.set(sqr_x1+(sqr_xdist*2),sqr_y1,20,20);
24484 8 flagsqr_pos.set(sqr_x1+(sqr_xdist*3),sqr_y1,20,20);
24485
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
40 for(auto q = 0; q < 4; ++q)
24486 {
24487 32 warpret_pos[q].set(sqr_x1+(sqr_xdist*q),sqr_y2,20,20);
24488 32 }
24489 8 enemy_prev_pos.set(sqr_x1+(sqr_xdist*4), sqr_y1, 4, 3, 16, 16);
24490 8 enemy_prev_pos.fw = enemy_prev_pos.xscale*2;
24491 8 enemy_prev_pos.fh = enemy_prev_pos.yscale*2;
24492 }
24493
24494 8 auto& last_alias_list = comboaliaslist[num_combo_cols-1];
24495 8 combopool_preview.x=comboaliaslist[0].x;
24496 8 combopool_preview.y=last_alias_list.y+(last_alias_list.h*last_alias_list.yscale)+16;
24497 8 combopool_preview.w=(last_alias_list.x+(last_alias_list.w*last_alias_list.xscale))-comboaliaslist[0].x;
24498 8 combopool_preview.h=zq_screen_h-8-combopool_preview.y;
24499 8 combopool_preview.w -= combopool_preview.w%16;
24500 8 combopool_preview.h -= combopool_preview.h%16;
24501
24502 8 FONT* tfont = get_zc_font(font_lfont_l);
24503 8 combopool_prevbtn.w = text_length(tfont, "Unweighted")+10;
24504 8 combopool_prevbtn.h = 11;
24505 8 combopool_prevbtn.x = combopool_preview.x;
24506 8 combopool_prevbtn.y = combopool_preview.y-combopool_prevbtn.h;
24507
24508 8 mappage_count = 6;
24509
24510 8 txfont = get_zc_font(font_lfont_l);
24511 8 combo_preview_text1.set(combo_preview.x-5,combo_preview.y,1,3,1,text_height(txfont));
24512 8 combo_preview_text2.clear();
24513
24514 8 favorites_x.w = 17;
24515 8 favorites_infobtn.w = 17;
24516 8 favorites_zoombtn.w = 17;
24517 8 favorites_pgleft.w = 17;
24518 8 favorites_pgright.w = 17;
24519 8 }
24520 else
24521 {
24522 num_combo_cols = 4;
24523 combo_col_scale = 16;
24524 if(large_merged_combopane)
24525 {
24526 num_combo_cols = 2;
24527 combo_col_scale = 32;
24528 }
24529
24530 mapscreen_x=0;
24531 mapscreen_y=dialogs[0].h;
24532 mapscreen_screenunit_scale=2;
24533 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
24534 showedges=Map.getViewSize() <= 2 ? 1 : 0;
24535 showallpanels=0;
24536
24537 blackout_color=8;
24538
24539 favorites_window.h=136;
24540 favorites_window.y=zq_screen_h-favorites_window.h;
24541
24542 auto mapscr_wid = (((2)+16)*16*mapscreen_screenunit_scale);
24543 combolist_window.w=zq_screen_w-mapscr_wid;
24544 combolist_window.x=zq_screen_w-combolist_window.w;
24545 combolist_window.y=0;
24546 combolist_window.h=favorites_window.y-combolist_window.y;
24547
24548 favorites_window.x=combolist_window.x;
24549 favorites_window.w=combolist_window.w;
24550
24551 combo_preview.x=(zq_screen_w-(combolist_window.w/2))-40;
24552 combo_preview.y=combolist_window.y+6;
24553 combo_preview.w=32;
24554 combo_preview.h=32;
24555 combo_preview2 = combo_preview;
24556 combo_preview2.x += 48;
24557
24558 auto col_wid = 4*combo_col_scale;
24559 auto cols_wid = col_wid * num_combo_cols;
24560 auto cols_spacing = (combolist_window.w-cols_wid)/(num_combo_cols+1);
24561 for(auto q = 0; q < num_combo_cols; ++q)
24562 {
24563 combolist[q].x=combolist_window.x+(cols_spacing*(q+1))+(col_wid*q);
24564 combolist[q].y=combolist_window.y+60;
24565 combolist[q].w=4;
24566 combolist[q].h=large_merged_combopane ? 15 : 30;
24567 combolist[q].xscale = combo_col_scale;
24568 combolist[q].yscale = combo_col_scale;
24569
24570 comboaliaslist[q].x=combolist[q].x;
24571 comboaliaslist[q].y=combolist[q].y;
24572 comboaliaslist[q].w=4;
24573 comboaliaslist[q].h=large_merged_combopane ? 12 : 25;
24574 comboaliaslist[q].xscale = combo_col_scale;
24575 comboaliaslist[q].yscale = combo_col_scale;
24576
24577 combolistscrollers[q].w=2;
24578 combolistscrollers[q].h=1;
24579 combolistscrollers[q].xscale=11;
24580 combolistscrollers[q].yscale=11;
24581 combolistscrollers[q].x=combolist[q].x+(combolist[q].w*combolist[q].xscale/2)-11;
24582 combolistscrollers[q].y=combolist[q].y-combolistscrollers[q].th()-2;
24583 }
24584
24585 comboalias_preview.x=zq_screen_w-((combolist_window.w+64)/2);
24586 comboalias_preview.h=64;
24587 comboalias_preview.w=64;
24588 comboalias_preview.y=favorites_window.y-comboalias_preview.h-8;
24589
24590 combo_merge_btn.w = 20;
24591 combo_merge_btn.h = 20;
24592 combo_merge_btn.x = zq_screen_w-(combolist_window.w+combo_merge_btn.w)/2;
24593 combo_merge_btn.y = combolist[0].y-combo_merge_btn.h;
24594 squarepanel_swap_btn.clear();
24595 squarepanel_up_btn.clear();
24596 squarepanel_down_btn.clear();
24597
24598 drawmode_btn.x = combolist_window.x-drawmode_wid;
24599 drawmode_btn.y = 0;
24600 drawmode_btn.w = drawmode_wid;
24601 drawmode_btn.h = mapscreen_y;
24602
24603 compactbtn.w = text_length(guifont,"> Compact")+10;
24604 compactbtn.x = drawmode_btn.x-compactbtn.w;
24605 compactbtn.y = drawmode_btn.y;
24606 compactbtn.h = drawmode_btn.h;
24607
24608 zoominbtn.w = text_length(guifont,"+")+10;
24609 zoominbtn.x = compactbtn.x-zoominbtn.w;
24610 zoominbtn.y = compactbtn.y;
24611 zoominbtn.h = compactbtn.h;
24612
24613 zoomoutbtn.w = text_length(guifont,"-")+10;
24614 zoomoutbtn.x = zoominbtn.x-zoomoutbtn.w;
24615 zoomoutbtn.y = compactbtn.y;
24616 zoomoutbtn.h = compactbtn.h;
24617
24618 for(int32_t i=0; i<=8; i++)
24619 {
24620 map_page_bar[i].x = mapscreen_x+(i*16*2*mapscreen_screenunit_scale);
24621 map_page_bar[i].y = mapscreen_y+((13)*16*mapscreen_screenunit_scale);
24622 map_page_bar[i].w = 64;
24623 map_page_bar[i].h = text_height(guifont)+12;
24624 }
24625
24626 minimap.w=7+48*3;
24627 minimap.h=16+27*3;
24628
24629 layer_panel.x=map_page_bar[0].x;
24630 layer_panel.y=map_page_bar[0].y+map_page_bar[0].h;
24631 layer_panel.w=map_page_bar[8].x+map_page_bar[8].w;
24632 layer_panel.h=text_height(guifont)+8;
24633 layerpanel_buttonwidth = 58;
24634 layerpanel_buttonheight = layer_panel.h;
24635 layerpanel_checkbox_hei = layerpanel_buttonheight-4;
24636 layerpanel_checkbox_wid = 14;
24637
24638 commands_list.w=4;
24639 commands_window.w=commands_list.w*commands_list.xscale+16;
24640 commands_window.x=combolist_window.x-commands_window.w;
24641 commands_window.y=layer_panel.y+layer_panel.h;
24642 commands_window.h=zq_screen_h-commands_window.y;
24643
24644 //buttons panel
24645 main_panel.x = 0;
24646 main_panel.y = layer_panel.y+layer_panel.h;
24647 main_panel.w = commands_window.x - main_panel.x;
24648 main_panel.h = zq_screen_h - main_panel.y;
24649 preview_panel = main_panel;
24650
24651 preview_text.x = preview_panel.x+3;
24652 preview_text.y = preview_panel.y+3;
24653 preview_text.w = 1;
24654 preview_text.h = 12;
24655 preview_text.xscale = 10;
24656 preview_text.yscale = text_height(get_zc_font(font_lfont_l));
24657
24658 minimap.x=3;
24659 minimap.y=main_panel.y+4;
24660
24661 real_minimap.x = minimap.x+3;
24662 real_minimap.y = minimap.y+5;
24663 real_minimap.w = 16;
24664 real_minimap.h = 9;
24665 real_minimap.xscale = 9;
24666 real_minimap.yscale = 9;
24667 real_minimap.fw = real_minimap.xscale*8;
24668 real_minimap.fh = real_minimap.yscale*8;
24669
24670 int upscale_mm = 4;
24671 int xwid = real_minimap.tw()*(upscale_mm-1);
24672 int xhei = real_minimap.th()*(upscale_mm-1);
24673 int zh = minimap.h+xhei+4;
24674 minimap_zoomed.set(minimap.x, zq_screen_h-zh, minimap.w+xwid, zh);
24675 real_minimap_zoomed.set(minimap_zoomed.x+3, minimap_zoomed.y+5, real_minimap.w, real_minimap.h, real_minimap.xscale*upscale_mm, real_minimap.yscale*upscale_mm);
24676 real_minimap_zoomed.fw = real_minimap_zoomed.xscale*8;
24677 real_minimap_zoomed.fh = real_minimap_zoomed.yscale*8;
24678
24679 screrrorpos.x = 575;
24680 screrrorpos.y = 388;
24681
24682 mouse_scroll_h=10;
24683
24684 favorites_list.x=favorites_window.x+8;
24685 favorites_list.y=favorites_window.y+16;
24686 favorites_list.xscale = 16;
24687 favorites_list.yscale = 16;
24688 favorites_list.w=(favorites_window.w-16)/favorites_list.xscale;
24689 favorites_list.h=(favorites_window.h-24)/favorites_list.yscale;
24690
24691 int bh = 16;
24692 int by = commands_window.y+4;
24693 commands_list.y=by+bh;
24694 commands_list.h=(zq_screen_h - commands_list.y) / commands_list.yscale;
24695 commands_list.x=commands_window.x+8;
24696
24697 commands_x.w = 20;
24698 commands_x.h = bh;
24699 commands_x.x = commands_list.x + commands_list.tw() - commands_x.w;
24700 commands_x.y = by;
24701
24702 commands_infobtn.w = 20;
24703 commands_infobtn.h = bh;
24704 commands_infobtn.x = commands_x.x - commands_infobtn.w;
24705 commands_infobtn.y = by;
24706
24707 commands_zoombtn.w = 20;
24708 commands_zoombtn.h = bh;
24709 commands_zoombtn.x = commands_infobtn.x - commands_zoombtn.w;
24710 commands_zoombtn.y = by;
24711
24712 commands_txt.x = commands_list.x;
24713 commands_txt.y = by+(bh-text_height(get_zc_font(font_lfont_l)))/2;
24714
24715 favorites_x.x = favorites_window.x + favorites_window.w - favorites_x.w - 2;
24716 favorites_x.y = favorites_list.y-15;
24717
24718 favorites_infobtn.x = favorites_x.x - favorites_infobtn.w;
24719 favorites_infobtn.y = favorites_x.y;
24720
24721 favorites_zoombtn.x = favorites_infobtn.x - favorites_zoombtn.w;
24722 favorites_zoombtn.y = favorites_infobtn.y;
24723
24724 favorites_pgright.x = favorites_zoombtn.x - favorites_pgright.w;
24725 favorites_pgright.y = favorites_zoombtn.y;
24726
24727 favorites_pgleft.x = favorites_pgright.x - favorites_pgleft.w;
24728 favorites_pgleft.y = favorites_pgleft.y;
24729
24730 txtoffs_single.x = 22;
24731 txtoffs_single.y = 6;
24732 txtoffs_double_1.x = 22;
24733 txtoffs_double_1.y = 2;
24734 txtoffs_double_2.x = 22;
24735 txtoffs_double_2.y = 10;
24736 panel_align = 0;
24737
24738 int sqx = minimap.x+minimap.tw();
24739 squares_panel.set(sqx,main_panel.y,main_panel.tw()-sqx,main_panel.th());
24740 int x2 = sqx+4;
24741 int x1 = x2 - (20+(8*3)+2);
24742 int y1 = main_panel.y+10;
24743 int sw = 20, sh = 20;
24744 int offs = sh+4;
24745
24746 itemsqr_pos.set(x2,y1+(0*offs),sw,sh);
24747 flagsqr_pos.set(x2,y1+(1*offs),sw,sh);
24748 stairsqr_pos.set(x2,y1+(2*offs),sw,sh);
24749 warparrival_pos.set(x2,y1+(6*offs),sw,sh);
24750
24751 enemy_prev_pos.x = main_panel.x+14;
24752 enemy_prev_pos.y = main_panel.y+12 + minimap.h;
24753 enemy_prev_pos.w = 4;
24754 enemy_prev_pos.h = 3;
24755 enemy_prev_pos.xscale = 16;
24756 enemy_prev_pos.yscale = 16;
24757 enemy_prev_pos.fw = enemy_prev_pos.xscale*2;
24758 enemy_prev_pos.fh = enemy_prev_pos.yscale*2;
24759
24760 warpret_pos[0].set(x1,y1+(4*offs),sw,sh);
24761 warpret_pos[1].set(x1,y1+(5*offs),sw,sh);
24762 warpret_pos[2].set(x2,y1+(4*offs),sw,sh);
24763 warpret_pos[3].set(x2,y1+(5*offs),sw,sh);
24764
24765 auto& last_alias_list = comboaliaslist[num_combo_cols-1];
24766 combopool_preview.x=comboaliaslist[0].x;
24767 combopool_preview.y=last_alias_list.y+(last_alias_list.h*last_alias_list.yscale)+16;
24768 combopool_preview.w=(last_alias_list.x+(last_alias_list.w*last_alias_list.xscale))-comboaliaslist[0].x;
24769 combopool_preview.h=(favorites_window.y-combopool_preview.y);//+favorites_window.h-10;
24770 combopool_preview.w -= combopool_preview.w%16;
24771 combopool_preview.h -= combopool_preview.h%16;
24772
24773 FONT* tfont = get_zc_font(font_lfont_l);
24774 combopool_prevbtn.w = text_length(tfont, "Unweighted")+10;
24775 combopool_prevbtn.h = 11;
24776 combopool_prevbtn.x = combopool_preview.x;
24777 combopool_prevbtn.y = combopool_preview.y-combopool_prevbtn.h;
24778
24779 mappage_count = 9;
24780
24781 txfont = get_zc_font(font_lfont_l);
24782 combo_preview_text1.set(combo_preview.x-9,combo_preview.y,1,3,1,text_height(txfont));
24783 combo_preview_text2.set(combo_preview2.x+combo_preview2.w+8,combo_preview2.y,1,3,1,text_height(txfont));
24784
24785 favorites_x.w = 30;
24786 favorites_infobtn.w = 30;
24787 favorites_zoombtn.w = 30;
24788 favorites_pgleft.w = 30;
24789 favorites_pgright.w = 30;
24790 }
24791 //Same in all modes
24792 {
24793
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(is_compact ? compact_zoomed_cmd : large_zoomed_cmd)
24794 {
24795 8 commands_list.w /= 2;
24796 8 commands_list.xscale *= 2;
24797 8 }
24798
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(is_compact ? compact_zoomed_fav : large_zoomed_fav)
24799 {
24800
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(favorites_list.w%2)
24801 favorites_list.x += (favorites_list.xscale / 2);
24802 8 favorites_list.xscale *= 2;
24803 8 favorites_list.yscale *= 2;
24804 8 favorites_list.w /= 2;
24805 8 favorites_list.h /= 2;
24806 8 }
24807
24808 8 favorites_x.h = 14;
24809 8 favorites_x.x = favorites_window.x + favorites_window.w - favorites_x.w - 2;
24810 8 favorites_x.y = favorites_list.y-15;
24811
24812 8 favorites_infobtn.h = favorites_x.h;
24813 8 favorites_infobtn.x = favorites_x.x - favorites_infobtn.w;
24814 8 favorites_infobtn.y = favorites_x.y;
24815
24816 8 favorites_zoombtn.h = favorites_infobtn.h;
24817 8 favorites_zoombtn.x = favorites_infobtn.x - favorites_zoombtn.w;
24818 8 favorites_zoombtn.y = favorites_infobtn.y;
24819
24820 8 favorites_pgright.h = favorites_zoombtn.h;
24821 8 favorites_pgright.x = favorites_zoombtn.x - favorites_pgright.w;
24822 8 favorites_pgright.y = favorites_zoombtn.y;
24823
24824 8 favorites_pgleft.h = favorites_pgright.h;
24825 8 favorites_pgleft.x = favorites_pgright.x - favorites_pgleft.w;
24826 8 favorites_pgleft.y = favorites_pgright.y;
24827
24828 8 mainbar.x = dialogs[0].x+dialogs[0].w;
24829 8 mainbar.y = 0;
24830 8 mainbar.w = zoomoutbtn.x-mainbar.x;
24831 8 mainbar.h = drawmode_btn.h;
24832 }
24833
24834 //Ensure current combo list selected is valid
24835 8 current_combolist=vbound(current_combolist,0,num_combo_cols-1);
24836 8 current_comboalist=vbound(current_comboalist,0,num_combo_cols-1);
24837 8 current_cpoollist=vbound(current_cpoollist,0,num_combo_cols-1);
24838 8 current_cautolist = vbound(current_cautolist, 0, num_combo_cols - 1);
24839
24840 //Generate bitmaps
24841 8 init_bitmap(&mapscreenbmp,16*(showedges?18:16),16*(showedges?13:11));
24842 8 init_bitmap(&brushbmp,256*mapscreen_screenunit_scale,176*mapscreen_screenunit_scale);
24843 8 init_bitmap(&brushscreen,(256+(showedges?16:0))*mapscreen_screenunit_scale,(176+(showedges?16:0))*mapscreen_screenunit_scale);
24844
24845 8 init_bitmap(&screen2,zq_screen_w,zq_screen_h);
24846 8 init_bitmap(&tmp_scr,zq_screen_w,zq_screen_h);
24847 8 init_bitmap(&menu1,zq_screen_w,zq_screen_h);
24848 8 init_bitmap(&menu3,zq_screen_w,zq_screen_h);
24849
24850 8 center_zq_class_dialogs();
24851 8 center_zq_files_dialogs();
24852 8 center_zq_subscreen_dialogs();
24853 8 center_zq_tiles_dialogs();
24854 8 center_zquest_dialogs();
24855
24856 8 aspect_ratio = zq_screen_h / double(zq_screen_w);
24857
24858 8 mmap_init();
24859 8 }
24860
24861 11 void remove_locked_params_on_exit()
24862 {
24863 11 al_trace("Removing timers. \n");
24864 11 remove_int(fps_callback);
24865 11 remove_int(dclick_check);
24866 11 }
24867
24868 11 void destroy_bitmaps_on_exit()
24869 {
24870 11 al_trace("Cleaning bitmaps...");
24871 11 destroy_bitmap(screen2);
24872 11 destroy_bitmap(tmp_scr);
24873 11 destroy_bitmap(menu1);
24874 11 destroy_bitmap(menu3);
24875 11 destroy_bitmap(mapscreenbmp);
24876 11 destroy_bitmap(dmapbmp_small);
24877 11 destroy_bitmap(dmapbmp_large);
24878 11 destroy_bitmap(brushbmp);
24879 11 destroy_bitmap(brushscreen);
24880 11 al_trace("...");
24881
24882
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 11 times.
539 for(int32_t i=0; i<MOUSE_BMP_MAX*4; i++)
24883 {
24884 528 destroy_bitmap(mouse_bmp[i/4][i%4]);
24885 528 destroy_bitmap(mouse_bmp_1x[i/4][i%4]);
24886 528 }
24887
24888
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 11 times.
363 for(int32_t i=0; i<ICON_BMP_MAX*4; i++)
24889 352 destroy_bitmap(icon_bmp[i/4][i%4]);
24890
24891
2/2
✓ Branch 0 taken 704 times.
✓ Branch 1 taken 11 times.
715 for(int32_t i=0; i<16*4; i++)
24892 704 destroy_bitmap(flag_bmp[i/4][i%4]);
24893
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 11 times.
33 for(int32_t i=0; i<2; i++)
24894 22 destroy_bitmap(select_bmp[i]);
24895
24896
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 11 times.
99 for(int32_t i=0; i<MAXARROWS; i++)
24897 88 destroy_bitmap(arrow_bmp[i]);
24898
24899 11 al_trace(" OK. \n");
24900 11 }
24901
24902
24903 11 void quit_game()
24904 {
24905 11 set_last_timed_save(nullptr);
24906 11 save_config_file();
24907 11 zc_set_palette(black_palette);
24908 11 zc_stop_midi();
24909
24910 11 remove_locked_params_on_exit();
24911
24912 11 al_trace("Cleaning sfx. \n");
24913
24914
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<WAV_COUNT; i++)
24915 {
24916
2/2
✓ Branch 0 taken 2805 times.
✓ Branch 1 taken 11 times.
2816 if(customsfxdata[i].data!=NULL)
24917 {
24918 // delete [] customsfxdata[i].data;
24919 2805 free(customsfxdata[i].data);
24920 2805 }
24921
24922
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] sfx_string[i];
24923 2816 }
24924
24925
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXWPNS; i++)
24926 {
24927
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] weapon_string[i];
24928 2816 }
24929
24930
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXITEMS; i++)
24931 {
24932
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] item_string[i];
24933 2816 }
24934
24935
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<eMAXGUYS; i++)
24936 {
24937
1/2
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
5632 delete [] guy_string[i];
24938 5632 }
24939
24940 11 al_trace("Cleaning script buffer. \n");
24941
24942
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
24943 {
24944
2/4
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5632 times.
5632 if(ffscripts[i]!=NULL) delete ffscripts[i];
24945 5632 }
24946
24947
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
24948 {
24949
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(itemscripts[i]!=NULL) delete itemscripts[i];
24950 2816 }
24951
24952
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
24953 {
24954
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(guyscripts[i]!=NULL) delete guyscripts[i];
24955 2816 }
24956
24957
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
24958 {
24959
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(lwpnscripts[i]!=NULL) delete lwpnscripts[i];
24960 2816 }
24961
24962
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
24963 {
24964
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(ewpnscripts[i]!=NULL) delete ewpnscripts[i];
24965 2816 }
24966
24967
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
24968 {
24969
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(screenscripts[i]!=NULL) delete screenscripts[i];
24970 2816 }
24971
24972
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 11 times.
44 for(int32_t i=0; i<3; i++) //should this be NUMSCRIPTGLOBAL or NUMSCRIPTGLOBALOLD? -Z
24973 {
24974
2/4
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 33 times.
33 if(globalscripts[i]!=NULL) delete globalscripts[i];
24975 33 }
24976
24977
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 11 times.
66 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
24978 {
24979
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 55 times.
55 if(playerscripts[i]!=NULL) delete playerscripts[i];
24980 55 }
24981
24982
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
24983 {
24984
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(dmapscripts[i]!=NULL) delete dmapscripts[i];
24985 2816 }
24986
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
24987 {
24988
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(itemspritescripts[i]!=NULL) delete itemspritescripts[i];
24989 2816 }
24990
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
24991 {
24992
2/4
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5632 times.
5632 if(comboscripts[i]!=NULL) delete comboscripts[i];
24993 5632 }
24994
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2816 times.
2827 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
24995 {
24996
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(subscreenscripts[i]!=NULL) delete subscreenscripts[i];
24997 2816 }
24998
24999 11 al_trace("Cleaning qst buffers. \n");
25000 11 del_qst_buffers();
25001
25002
25003 11 al_trace("Cleaning midis. \n");
25004
25005
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(customtunes)
25006 {
25007
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; i++)
25008 2816 customtunes[i].reset();
25009
25010 11 free(customtunes);
25011 11 }
25012
25013 11 al_trace("Cleaning undotilebuf. \n");
25014
25015 11 undocombobuf.clear();
25016
25017
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 if(newundotilebuf)
25018 {
25019
2/2
✓ Branch 0 taken 1716000 times.
✓ Branch 1 taken 8 times.
1716008 for(int32_t i=0; i<NEWMAXTILES; i++)
25020
1/2
✓ Branch 0 taken 1716000 times.
✗ Branch 1 not taken.
1716000 if(newundotilebuf[i].data) free(newundotilebuf[i].data);
25021
25022 8 free(newundotilebuf);
25023 8 }
25024
25025
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(filepath) free(filepath);
25026
25027
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(datapath) free(datapath);
25028
25029
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(midipath) free(midipath);
25030
25031
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(imagepath) free(imagepath);
25032
25033
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(tmusicpath) free(tmusicpath);
25034
25035
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(last_timed_save) free(last_timed_save);
25036
25037 11 destroy_bitmaps_on_exit();
25038 11 }
25039
25040 void quit_game2()
25041 {
25042 set_last_timed_save(nullptr);
25043 save_config_file();
25044 zc_set_palette(black_palette);
25045 zc_stop_midi();
25046
25047 remove_locked_params_on_exit();
25048
25049 al_trace("Cleaning sfx. \n");
25050
25051 for(int32_t i=0; i<WAV_COUNT; i++)
25052 {
25053 if(customsfxdata[i].data!=NULL)
25054 {
25055 // delete [] customsfxdata[i].data;
25056 free(customsfxdata[i].data);
25057 }
25058
25059 delete [] sfx_string[i];
25060 }
25061
25062 for(int32_t i=0; i<MAXWPNS; i++)
25063 {
25064 delete [] weapon_string[i];
25065 }
25066
25067 for(int32_t i=0; i<MAXITEMS; i++)
25068 {
25069 delete [] item_string[i];
25070 }
25071
25072 for(int32_t i=0; i<eMAXGUYS; i++)
25073 {
25074 delete [] guy_string[i];
25075 }
25076
25077 al_trace("Cleaning script buffer. \n");
25078
25079 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
25080 {
25081 if(ffscripts[i]!=NULL) delete ffscripts[i];
25082 }
25083
25084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
25085 {
25086 if(itemscripts[i]!=NULL) delete itemscripts[i];
25087 }
25088
25089 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
25090 {
25091 if(guyscripts[i]!=NULL) delete guyscripts[i];
25092 }
25093
25094 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25095 {
25096 if(lwpnscripts[i]!=NULL) delete lwpnscripts[i];
25097 }
25098
25099 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25100 {
25101 if(ewpnscripts[i]!=NULL) delete ewpnscripts[i];
25102 }
25103
25104 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
25105 {
25106 if(screenscripts[i]!=NULL) delete screenscripts[i];
25107 }
25108
25109 for(int32_t i=0; i<3; i++) //should this be NUMSCRIPTGLOBAL or NUMSCRIPTGLOBALOLD? -Z
25110 {
25111 if(globalscripts[i]!=NULL) delete globalscripts[i];
25112 }
25113
25114 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
25115 {
25116 if(playerscripts[i]!=NULL) delete playerscripts[i];
25117 }
25118
25119 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
25120 {
25121 if(dmapscripts[i]!=NULL) delete dmapscripts[i];
25122 }
25123 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
25124 {
25125 if(itemspritescripts[i]!=NULL) delete itemspritescripts[i];
25126 }
25127 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
25128 {
25129 if(comboscripts[i]!=NULL) delete comboscripts[i];
25130 }
25131 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
25132 {
25133 if(subscreenscripts[i]!=NULL) delete subscreenscripts[i];
25134 }
25135
25136 al_trace("Cleaning qst buffers. \n");
25137 del_qst_buffers();
25138
25139
25140 al_trace("Cleaning midis. \n");
25141
25142 if(customtunes)
25143 {
25144 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; i++)
25145 customtunes[i].reset();
25146
25147 free(customtunes);
25148 }
25149
25150 al_trace("Cleaning undotilebuf. \n");
25151
25152 undocombobuf.clear();
25153
25154 if(newundotilebuf)
25155 {
25156 for(int32_t i=0; i<NEWMAXTILES; i++)
25157 if(newundotilebuf[i].data) free(newundotilebuf[i].data);
25158
25159 free(newundotilebuf);
25160 }
25161
25162 if(filepath) free(filepath);
25163
25164 if(datapath) free(datapath);
25165
25166 if(midipath) free(midipath);
25167
25168 if(imagepath) free(imagepath);
25169
25170 if(tmusicpath) free(tmusicpath);
25171
25172 if(last_timed_save) free(last_timed_save);
25173 }
25174
25175 8 void center_zquest_dialogs()
25176 {
25177 8 jwin_center_dialog(assignscript_dlg);
25178 8 jwin_center_dialog(autolayer_dlg);
25179 8 center_zq_cset_dialogs();
25180 8 jwin_center_dialog(change_track_dlg);
25181 8 jwin_center_dialog(csetfix_dlg);
25182 8 jwin_center_dialog(dmapmaps_dlg);
25183 8 center_zq_door_dialogs();
25184 8 jwin_center_dialog(editcomboa_dlg);
25185 8 jwin_center_dialog(editinfo_dlg);
25186 8 jwin_center_dialog(editmusic_dlg);
25187 8 jwin_center_dialog(editshop_dlg);
25188 8 jwin_center_dialog(ffcombo_sel_dlg);
25189 8 jwin_center_dialog(getnum_dlg);
25190 8 jwin_center_dialog(layerdata_dlg);
25191 8 jwin_center_dialog(list_dlg);
25192 8 jwin_center_dialog(loadmap_dlg);
25193 8 jwin_center_dialog(misccolors_dlg);
25194 8 jwin_center_dialog(newcomboa_dlg);
25195 8 jwin_center_dialog(orgcomboa_dlg);
25196 8 jwin_center_dialog(path_dlg);
25197 8 jwin_center_dialog(screen_pal_dlg);
25198 8 jwin_center_dialog(secret_dlg);
25199 8 jwin_center_dialog(selectmusic_dlg);
25200 8 jwin_center_dialog(showpal_dlg);
25201 8 jwin_center_dialog(strlist_dlg);
25202 8 jwin_center_dialog(template_dlg);
25203 8 jwin_center_dialog(tp_dlg);
25204 8 jwin_center_dialog(under_dlg);
25205 8 jwin_center_dialog(tilewarp_dlg);
25206 8 jwin_center_dialog(sidewarp_dlg);
25207 8 jwin_center_dialog(warpring_dlg);
25208 8 center_zscript_dialogs();
25209 8 }
25210
25211
25212 void animate_coords()
25213 {
25214 coord_frame=(coord_timer>>3)&3;
25215
25216 if(++coord_timer>=(1<<5))
25217 {
25218 coord_timer=0;
25219 }
25220 }
25221
25222 static const char *help_list[] =
25223 {
25224 "PREVIEW MODE",
25225 "PgUp/PgDn - Scroll through hotkey list",
25226 "Esc/Enter - Exit Preview Mode",
25227 "R - Restore screen to original state",
25228 "C - Toggle combo cycling On/Off",
25229 "S - Trigger screen secrets",
25230 "Q/W/F - These still work",
25231 "P - Pause everything",
25232 "A - Advance frame-by-frame",
25233 "1-4 - Trigger tile warp A-D",
25234 "5-8 - Trigger side warp A-D",
25235 "9 - Enable timed warps",
25236 "",
25237 "",
25238 };
25239
25240 void do_previewtext()
25241 {
25242 FONT* oldfont = font;
25243 font = get_zc_font(font_lfont_l);
25244
25245 //Put in help areas
25246 auto& sqr = preview_text;
25247 int ind = 0, len = 0;
25248 for(int q = 0; q < 12; ++q)
25249 {
25250 int l = text_length(font, help_list[q]);
25251 if(len < l) len = l;
25252 }
25253 sqr.xscale = len+2;
25254 sqr.yscale = text_height(font);
25255 for(int col = 0; col < sqr.w; ++col)
25256 {
25257 for(int row = 0; row < sqr.h; ++row)
25258 {
25259 auto& line = sqr.subsquare(col,row);
25260 textprintf_ex(menu1,font,line.x,line.y,jwin_pal[jcTEXTFG],-1,"%s",help_list[ind++]);
25261 }
25262 }
25263
25264 font = oldfont;
25265 }
25266
25267
25268 bool reload_fonts = false;
25269 void run_zq_frame()
25270 {
25271 if(reload_fonts)
25272 {
25273 init_custom_fonts();
25274 load_size_poses();
25275 reload_fonts = false;
25276 }
25277
25278 domouse();
25279 custom_vsync();
25280 refresh(rCLEAR|rALL);
25281 }
25282 8 int32_t d_nbmenu_proc(int32_t msg,DIALOG *d,int32_t c)
25283 {
25284
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 switch(msg)
25285 {
25286 case MSG_VSYNC:
25287 run_zq_frame();
25288 break;
25289 case MSG_GOTMOUSE:
25290 case MSG_XCHAR:
25291 ComboBrushPause=1;
25292 refresh(rMAP);
25293 ComboBrushPause=0;
25294 clear_tooltip();
25295 break;
25296 }
25297
25298 8 return GuiMenu::proc(msg,d,c);
25299 }
25300
25301 bool prv_press=false;
25302
25303 void dopreview()
25304 {
25305 refresh(rMAP);
25306
25307 while(!(gui_mouse_b()))
25308 {
25309 if(keypressed())
25310 {
25311 if(!prv_press)
25312 {
25313 prv_press=true;
25314
25315 switch(readkey()>>8)
25316 {
25317 case KEY_ESC:
25318 case KEY_ENTER:
25319 case KEY_ENTER_PAD:
25320 goto finished;
25321 break;
25322
25323 case KEY_F:
25324 Flags^=cFLAGS;
25325 refresh(rMAP);
25326 break;
25327
25328 case KEY_R:
25329 onReloadPreview();
25330 break;
25331
25332 case KEY_S:
25333 onSecretsPreview();
25334 break;
25335
25336 case KEY_C:
25337 onCopy();
25338 break;
25339
25340 case KEY_A:
25341 onAKey();
25342 break;
25343
25344 case KEY_P:
25345 onP();
25346 break;
25347
25348 case KEY_L:
25349 onShowDarkness();
25350 break;
25351
25352 case KEY_1:
25353 Map.prv_dowarp(0,0);
25354 prv_warp=0;
25355 break;
25356
25357 case KEY_2:
25358 Map.prv_dowarp(0,1);
25359 prv_warp=0;
25360 break;
25361
25362 case KEY_3:
25363 Map.prv_dowarp(0,2);
25364 prv_warp=0;
25365 break;
25366
25367 case KEY_4:
25368 Map.prv_dowarp(0,3);
25369 prv_warp=0;
25370 break;
25371
25372 case KEY_5:
25373 Map.prv_dowarp(1,0);
25374 prv_warp=0;
25375 break;
25376
25377 case KEY_6:
25378 Map.prv_dowarp(1,1);
25379 prv_warp=0;
25380 break;
25381
25382 case KEY_7:
25383 Map.prv_dowarp(1,2);
25384 prv_warp=0;
25385 break;
25386
25387 case KEY_8:
25388 Map.prv_dowarp(1,3);
25389 prv_warp=0;
25390 break;
25391
25392 case KEY_9:
25393 if(prv_twon)
25394 {
25395 prv_twon=0;
25396 Map.set_prvtime(0);
25397 prv_warp=0;
25398 }
25399 else
25400 {
25401 Map.set_prvtime(Map.get_prvscr()->timedwarptics);
25402 prv_twon=1;
25403 }
25404
25405 break;
25406
25407 case KEY_W:
25408 onShowWalkability();
25409 break;
25410
25411 case KEY_Q:
25412 onShowComboInfoCSet();
25413 break;
25414 }
25415 }
25416 else
25417 {
25418 readkey();
25419 }
25420 }
25421 else
25422 {
25423 prv_press=false;
25424 }
25425
25426 if(prv_warp)
25427 {
25428 Map.prv_dowarp(1,0);
25429 prv_warp=0;
25430 }
25431
25432 if(Map.get_prvfreeze())
25433 {
25434 if(Map.get_prvadvance())
25435 {
25436 custom_vsync();
25437 Map.set_prvadvance(0);
25438 }
25439 }
25440 else
25441 {
25442 custom_vsync();
25443 Map.set_prvadvance(0);
25444 }
25445
25446 refresh(rALL);
25447 }
25448
25449 finished:
25450 //Flags=of;
25451 reset_combo_animations();
25452 reset_combo_animations2();
25453 MouseSprite::set(ZQM_NORMAL);
25454 prv_mode=0;
25455 prv_warp=0;
25456 Map.end_prv();
25457 Map.refresh_color();
25458 refresh(rMAP+rMENU);
25459
25460 while(gui_mouse_b())
25461 {
25462 /* do nothing */
25463 rest(1);
25464 }
25465 }
25466
25467 void call_vidmode_dlg();
25468 int32_t onZQVidMode()
25469 {
25470 call_vidmode_dlg();
25471 return D_O_K;
25472 }
25473
25474 bool screenIsScrolling()
25475 {
25476 return false;
25477 }
25478
25479 void write_includepaths()
25480 {
25481 FILE* f = fopen("includepaths.txt", "w");
25482 if(f)
25483 {
25484 fwrite(FFCore.includePathString,1,strlen(FFCore.includePathString),f);
25485 fclose(f);
25486 }
25487 }
25488
25489 11 int32_t save_config_file()
25490 {
25491
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!application_has_loaded) return 0;
25492
25493 char qtnametitle[20];
25494 char qtpathtitle[20];
25495 char *datapath2=(char *)malloc(2048);
25496 char *midipath2=(char *)malloc(2048);
25497 char *imagepath2=(char *)malloc(2048);
25498 char *tmusicpath2=(char *)malloc(2048);
25499 strcpy(datapath2, datapath);
25500 strcpy(midipath2, midipath);
25501 strcpy(imagepath2, imagepath);
25502 strcpy(tmusicpath2, tmusicpath);
25503 chop_path(datapath2);
25504 chop_path(midipath2);
25505 chop_path(imagepath2);
25506 chop_path(tmusicpath2);
25507 write_includepaths();
25508
25509 zc_set_config("zquest",data_path_name,datapath2);
25510 zc_set_config("zquest",midi_path_name,midipath2);
25511 zc_set_config("zquest",image_path_name,imagepath2);
25512 zc_set_config("zquest",tmusic_path_name,tmusicpath2);
25513
25514 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
25515 {
25516 window_width = al_get_display_width(all_get_display());
25517 window_height = al_get_display_height(all_get_display());
25518 zc_set_config("zquest","window_width",window_width);
25519 zc_set_config("zquest","window_height",window_height);
25520 }
25521 if (all_get_display() && !all_get_fullscreen_flag() && SaveWinPos)
25522 {
25523 int o_window_x, o_window_y;
25524 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
25525 zc_set_config("zquest", "window_x", o_window_x);
25526 zc_set_config("zquest", "window_y", o_window_y);
25527 }
25528
25529 byte b = 0;
25530 for(int32_t x=0; x<7; x++)
25531 {
25532 set_bit(&b,x,LayerMaskInt[x]);
25533 }
25534
25535 zc_set_config("zquest","layer_mask",b);
25536
25537 flush_config_file();
25538 #ifdef __EMSCRIPTEN__
25539 em_sync_fs();
25540 #endif
25541 free(datapath2);
25542 free(midipath2);
25543 free(imagepath2);
25544 free(tmusicpath2);
25545 return 0;
25546 11 }
25547
25548 int32_t d_timer_proc(int32_t msg, DIALOG *d, int32_t c)
25549 {
25550 //these are here to bypass compiler warnings about unused arguments
25551 c=c;
25552 d=d;
25553
25554 switch(msg)
25555 {
25556 case MSG_IDLE:
25557 #ifdef _WIN32
25558 if(zqUseWin32Proc != FALSE)
25559 win32data.Update(Frameskip); //experimental win32 fixes
25560
25561 #endif
25562
25563 // This has been crashing on Windows, and it saves plenty without it
25564 //check_autosave();
25565 break;
25566 }
25567
25568 return D_O_K;
25569 }
25570
25571 void check_autosave()
25572 {
25573 if (!first_save)
25574 return;
25575
25576 if(AutoSaveInterval>0)
25577 {
25578 time(&auto_save_time_current);
25579 auto_save_time_diff = difftime(auto_save_time_current,auto_save_time_start);
25580
25581 if(auto_save_time_diff>AutoSaveInterval*60)
25582 {
25583 MouseSprite::set(ZQM_NORMAL);
25584 replace_extension(last_timed_save, filepath, "qt0", 2047);
25585 set_last_timed_save(last_timed_save);
25586 go();
25587
25588 if((header.zelda_version != ZELDA_VERSION || header.build != VERSION_BUILD))
25589 {
25590 jwin_alert("Auto Save","This quest was saved in an older version of ZQuest.","If you wish to use the autosave feature, you must manually","save the files in this version first.","OK",NULL,13,27,get_zc_font(font_lfont));
25591 time(&auto_save_time_start);
25592 comeback();
25593 return;
25594 }
25595
25596 int32_t ret = save_quest(last_timed_save, true);
25597
25598 if(ret)
25599 {
25600 jwin_alert("Error","Timed save did not complete successfully.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
25601 set_last_timed_save(nullptr);
25602 }
25603
25604 save_config_file();
25605 time(&auto_save_time_start);
25606 comeback();
25607 }
25608 }
25609 }
25610
25611 void flushItemCache(bool) {}
25612 void ringcolor(bool forceDefault)
25613 {
25614 forceDefault=forceDefault;
25615 }
25616
25617 bool item_disabled(int32_t)
25618 {
25619 return false;
25620 }
25621
25622 int32_t onCmdExit()
25623 {
25624 // replaces onExit for the -large button command "Exit"
25625 close_button_quit = true;
25626 return 0;
25627 }
25628
25629 int32_t onQuickCompile()
25630 {
25631 if(do_compile_and_slots(1,false))
25632 {
25633 saved = false;
25634 InfoDialog("Quick Compile","Success!").show();
25635 }
25636 else
25637 {
25638 InfoDialog("Quick Compile","Failure!").show();
25639 }
25640 return 0;
25641 }
25642 int32_t onSmartCompile()
25643 {
25644 if(do_compile_and_slots(2,false))
25645 {
25646 saved = false;
25647 InfoDialog("Smart Compile","Success!").show();
25648 }
25649 else
25650 {
25651 InfoDialog("Smart Compile","Failure!").show();
25652 }
25653 return 0;
25654 }
25655
25656 int32_t strchrnum(char const* str, char c)
25657 {
25658 for(int32_t i=0; str[i]; ++i)
25659 {
25660 if(str[i]==c)
25661 {
25662 return i;
25663 }
25664 }
25665
25666 return -1;
25667 }
25668
25669 int32_t get_longest_line_length(FONT *f, char* str)
25670 {
25671 int32_t maxlen=0;
25672 char* tmpstr = str;
25673 char temp=0;
25674 int32_t t=0;
25675 int32_t new_t=-1;
25676 while(tmpstr[0])
25677 {
25678 t=strchrnum(tmpstr, '\n');
25679
25680 if(t==-1)
25681 {
25682 t=(int32_t)strlen(tmpstr);
25683 }
25684
25685 if((uint32_t)t!=strlen(tmpstr))
25686 {
25687 new_t=t+1;
25688 }
25689 else
25690 {
25691 new_t=-1;
25692 }
25693
25694 temp = tmpstr[t];
25695 tmpstr[t]=0;
25696 maxlen=zc_max(maxlen,text_length(f, tmpstr));
25697 tmpstr[t]=temp;
25698
25699 if(new_t!=-1)
25700 {
25701 tmpstr+=new_t;
25702 }
25703 else break;
25704 }
25705 return maxlen;
25706 }
25707
25708 int32_t count_lines(char const* str)
25709 {
25710 int32_t count=1;
25711
25712 for(word i=0; i<strlen(str); ++i)
25713 {
25714 if(str[i]=='\n')
25715 {
25716 ++count;
25717 }
25718 }
25719
25720 return count;
25721 }
25722
25723 void debug_pos(size_and_pos const& pos, int color)
25724 {
25725 if(pos.w < 1 || pos.h < 1)
25726 return;
25727 if(pos.xscale > 1 || pos.yscale > 1)
25728 {
25729 auto maxind = pos.w*pos.h;
25730 for(auto q = 0; q < maxind; ++q)
25731 {
25732 auto& sub = pos.subsquare(q);
25733 if(sub.x < 0) break;
25734 highlight_sqr(screen, color, sub, 1);
25735 }
25736 }
25737 else
25738 {
25739 if(pos.fw > -1 && pos.fh > -1)
25740 highlight_frag(screen, color, pos, 1);
25741 else highlight_sqr(screen, color, pos, 1);
25742 }
25743 }
25744
25745 void textbox_out(BITMAP* dest, FONT* font, int x, int y, int fg, int bg, char const* str, int align, size_and_pos* dims)
25746 {
25747 static size_and_pos nilsz;
25748 size_and_pos& txbox = dims ? *dims : nilsz;
25749
25750 char* kill = (char*)malloc(strlen(str)+1);
25751 char *tmpstr = kill;
25752 strcpy(tmpstr,str);
25753
25754 while(tmpstr[0] == '\n')
25755 ++tmpstr;
25756 int len = strlen(tmpstr);
25757 while(tmpstr[len-1] == '\n')
25758 tmpstr[--len] = 0;
25759
25760 txbox.x=x;
25761 txbox.y=y;
25762 int32_t lines=count_lines(tmpstr);
25763 txbox.w = 1;
25764 txbox.h = lines;
25765 txbox.xscale = get_longest_line_length(font, tmpstr);
25766 txbox.yscale = text_height(font);
25767
25768 int ax = 0; //Aligned x
25769 switch(align)
25770 {
25771 case 0: //left
25772 break;
25773 case 1: //center
25774 txbox.x -= txbox.xscale/2;
25775 ax = txbox.xscale/2;
25776 break;
25777 case 2: //right
25778 txbox.x -= txbox.xscale;
25779 ax = txbox.xscale;
25780 break;
25781 }
25782
25783 int bw = txbox.w*txbox.xscale;
25784 int bh = txbox.h*txbox.yscale;
25785 BITMAP* outbmp = create_bitmap_ex(8, bw, bh);
25786 clear_to_color(outbmp, bg);
25787
25788 char temp = 0;
25789 int32_t t=0;
25790 int32_t new_t=-1;
25791 int32_t line=0;
25792
25793 while(tmpstr[t])
25794 {
25795 t=strchrnum(tmpstr, '\n');
25796
25797 if(t==-1)
25798 t=(int32_t)strlen(tmpstr);
25799
25800 if((uint32_t)t!=strlen(tmpstr))
25801 new_t=t+1;
25802 else
25803 new_t=-1;
25804
25805 temp = tmpstr[t];
25806 tmpstr[t]=0;
25807 gui_textout_ln(outbmp, font, (ucc*)tmpstr, ax, (line*txbox.yscale), fg, -1, align);
25808 tmpstr[t]=temp;
25809 ++line;
25810
25811 if(new_t!=-1)
25812 {
25813 tmpstr+=new_t;
25814 t=0;
25815 }
25816 }
25817
25818 blit(outbmp, dest, 0, 0, txbox.x, txbox.y, bw, bh);
25819 destroy_bitmap(outbmp);
25820 free(kill);
25821 }
25822
25823 void highlight_sqr(BITMAP* dest, int color, int x, int y, int w, int h, int thick)
25824 {
25825 for(int q = 0; q < thick; ++q)
25826 {
25827 safe_rect(dest, x+q, y+q, x+w-1-q, y+h-1-q, color);
25828 }
25829 }
25830 void highlight_sqr(BITMAP* dest, int color, size_and_pos const& rec, int thick)
25831 {
25832 highlight_sqr(dest, color, rec.x, rec.y, rec.tw(), rec.th(), thick);
25833 }
25834 void highlight_frag(BITMAP* dest, int color, int x1, int y1, int w, int h, int fw, int fh, int thick)
25835 {
25836 int xc = x1+fw-1;
25837 int yc = y1+fh-1;
25838 int x2 = x1+w-1;
25839 int y2 = y1+h-1;
25840
25841 hline(dest, x1, y1, x2, color);
25842 vline(dest, x1, y1, y2, color);
25843
25844 hline(dest, x1, y2, xc, color);
25845 vline(dest, x2, y1, yc, color);
25846 hline(dest, xc, yc, x2, color);
25847 vline(dest, xc, yc, y2, color);
25848 }
25849 void highlight_frag(BITMAP* dest, int color, size_and_pos const& rec, int thick)
25850 {
25851 highlight_frag(dest, color, rec.x, rec.y, rec.tw(), rec.th(), rec.fw, rec.fh, thick);
25852 }
25853
25854 void highlight(BITMAP* dest, size_and_pos& hl)
25855 {
25856 if(hl.fw > -1 && hl.fh > -1)
25857 {
25858 highlight_frag(dest, hl.data[1], hl, hl.data[0]);
25859 }
25860 else highlight_sqr(dest, hl.data[1], hl, hl.data[0]);
25861 }
25862
25863 std::pair<int, int> get_box_text_size(char const* tipmsg, double txscale)
25864 {
25865 if(txscale < 1) txscale = 1;
25866 char* kill = (char*)malloc(strlen(tipmsg)+1);
25867 char *tmpstr = kill;
25868 strcpy(tmpstr,tipmsg);
25869
25870 while(tmpstr[0] == '\n')
25871 ++tmpstr;
25872 int len = strlen(tmpstr);
25873 while(tmpstr[len-1] == '\n')
25874 tmpstr[--len] = 0;
25875
25876 int32_t lines = count_lines(tmpstr);
25877 int txlen = get_longest_line_length(font, tmpstr);
25878 int txhei = lines*text_height(font);
25879 int tx_sclen = (txlen * txscale);
25880 int tx_schei = (txhei * txscale);
25881 int w = tx_sclen + 8 + 1;
25882 int h = tx_schei + 8 + 1;
25883 if (w > zq_screen_w)
25884 w = zq_screen_w;
25885 if (h > zq_screen_h)
25886 h = zq_screen_h;
25887 return {w, h};
25888 }
25889
25890 void draw_box(BITMAP* destbmp, size_and_pos* pos, char const* tipmsg, double txscale)
25891 {
25892 if(txscale < 1) txscale = 1;
25893 char* kill = (char*)malloc(strlen(tipmsg)+1);
25894 char *tmpstr = kill;
25895 strcpy(tmpstr,tipmsg);
25896
25897 while(tmpstr[0] == '\n')
25898 ++tmpstr;
25899 int len = strlen(tmpstr);
25900 while(tmpstr[len-1] == '\n')
25901 tmpstr[--len] = 0;
25902
25903 auto& box = *pos;
25904 clear_bitmap(destbmp);
25905
25906 int32_t lines=count_lines(tmpstr);
25907 int txlen = get_longest_line_length(font, tmpstr);
25908 int txhei = lines*text_height(font);
25909 int tx_sclen = (txlen * txscale);
25910 int tx_schei = (txhei * txscale);
25911 box.w = tx_sclen + 8 + 1;
25912 box.h = tx_schei + 8 + 1;
25913 if (box.w > zq_screen_w)
25914 box.w = zq_screen_w;
25915 if (box.h > zq_screen_h)
25916 box.h = zq_screen_h;
25917
25918 if(box.x+box.w>=zq_screen_w)
25919 {
25920 box.x=(zq_screen_w - box.w);
25921 }
25922
25923 if(box.y+box.h>=zq_screen_h)
25924 {
25925 box.y=(zq_screen_h - box.h);
25926 }
25927
25928 rectfill(destbmp, 1, 1, box.w-3, box.h-3, jwin_pal[jcTEXTBG]);
25929 rect(destbmp, 0, 0, box.w-2, box.h-2, jwin_pal[jcTEXTFG]);
25930 vline(destbmp, box.w-1, 0, box.h-1, jwin_pal[jcTEXTFG]);
25931 hline(destbmp, 1, box.h-1, box.w-2, jwin_pal[jcTEXTFG]);
25932 destbmp->line[box.h-1][0]=0;
25933 destbmp->line[0][box.w-1]=0;
25934
25935 char temp = 0;
25936 int32_t t=0;
25937 int32_t new_t=-1;
25938 int32_t line=0;
25939
25940 BITMAP* txbmp = create_bitmap_ex(8,box.w,box.h);
25941 clear_bitmap(txbmp);
25942 while(tmpstr[t])
25943 {
25944 t=strchrnum(tmpstr, '\n');
25945
25946 if(t==-1)
25947 {
25948 t=(int32_t)strlen(tmpstr);
25949 }
25950
25951 if((uint32_t)t!=strlen(tmpstr))
25952 {
25953 new_t=t+1;
25954 }
25955 else
25956 {
25957 new_t=-1;
25958 }
25959
25960 temp = tmpstr[t];
25961 tmpstr[t]=0;
25962 textprintf_ex(txbmp, font, 0, (line*text_height(font)), jwin_pal[jcTEXTFG], -1, "%s", tmpstr);
25963 tmpstr[t]=temp;
25964 ++line;
25965
25966 if(new_t!=-1)
25967 {
25968 tmpstr+=new_t;
25969 t=0;
25970 }
25971 }
25972 masked_stretch_blit(txbmp,destbmp,0,0,txlen,txhei,4,4,tx_sclen,tx_schei);
25973 destroy_bitmap(txbmp);
25974 free(kill);
25975 }
25976
25977 void update_tooltip(int32_t x, int32_t y, size_and_pos const& sqr, char const* tipmsg, double scale)
25978 {
25979 update_tooltip(x,y,sqr.x,sqr.y,sqr.w*sqr.xscale,sqr.h*sqr.yscale,tipmsg,sqr.fw,sqr.fh,scale);
25980 }
25981 void update_tooltip(int32_t x, int32_t y, int32_t tx, int32_t ty, int32_t tw, int32_t th, char const* tipmsg, int fw, int fh, double scale)
25982 {
25983 if(!EnableTooltips)
25984 {
25985 return;
25986 }
25987
25988 ttip_install(ttip_global_id, tipmsg, tx, ty, tw, th, x, y, fw, fh);
25989 }
25990
25991 void ZQ_ClearQuestPath()
25992 {
25993 zc_set_config("zquest","win_last_quest",(char const*)nullptr);
25994 strcpy(filepath,"");
25995 }
25996
25997 //FFCore
25998
25999 void FFScript::init()
26000 {
26001 for ( int32_t q = 0; q < wexLast; q++ ) warpex[q] = 0;
26002 numscriptdraws = 0;
26003 max_ff_rules = qr_MAX;
26004 temp_no_stepforward = 0;
26005 nostepforward = 0;
26006
26007 coreflags = 0;
26008 skip_ending_credits = 0;
26009 music_update_cond = 0;
26010 music_update_flags = 0;
26011 for ( int32_t q = 0; q < susptLAST; q++ ) { system_suspend[q] = false; }
26012
26013 //for ( int32_t q = 0; q < 512; q++ ) FF_rules[q] = 0;
26014 int32_t usr_midi_volume = usr_digi_volume = usr_sfx_volume = usr_music_volume = usr_panstyle = 0;
26015 FF_hero_action = 0;
26016 enemy_removal_point[spriteremovalY1] = -32767;
26017 enemy_removal_point[spriteremovalY2] = 32767;
26018 enemy_removal_point[spriteremovalX1] = -32767;
26019 enemy_removal_point[spriteremovalX2] = 32767;
26020 enemy_removal_point[spriteremovalZ1] = -32767;
26021 enemy_removal_point[spriteremovalZ2] = 32767;
26022
26023 for ( int32_t q = 0; q < 4; q++ )
26024 {
26025 FF_screenbounds[q] = 0;
26026 FF_screen_dimensions[q] = 0;
26027 FF_subscreen_dimensions[q] = 0;
26028 FF_eweapon_removal_bounds[q] = 0;
26029 FF_lweapon_removal_bounds[q] = 0;
26030 }
26031 for ( int32_t q = 0; q < FFSCRIPTCLASS_CLOCKS; q++ )
26032 {
26033 FF_clocks[q] = 0;
26034 }
26035 for ( int32_t q = 0; q < SCRIPT_DRAWING_RULES; q++ )
26036 {
26037 ScriptDrawingRules[q] = 0;
26038 }
26039 for ( int32_t q = 0; q < NUM_USER_MIDI_OVERRIDES; q++ )
26040 {
26041 FF_UserMidis[q] = 0;
26042 }
26043 subscreen_scroll_speed = 0; //make a define for a default and read quest override! -Z
26044 kb_typing_mode = false;
26045 initIncludePaths();
26046 }
26047
26048 void FFScript::updateIncludePaths()
26049 {
26050 includePaths.clear();
26051 int32_t pos = 0; int32_t pathnumber = 0;
26052 for ( int32_t q = 0; includePathString[pos]; ++q )
26053 {
26054 int32_t dest = 0;
26055 char buf[2048] = {0};
26056 while(includePathString[pos] != ';' && includePathString[pos])
26057 {
26058 buf[dest] = includePathString[pos];
26059 ++pos;
26060 ++dest;
26061 }
26062 ++pos;
26063 string str(buf);
26064 includePaths.push_back(str);
26065 }
26066 }
26067
26068 void FFScript::initIncludePaths()
26069 {
26070 memset(includePathString,0,sizeof(includePathString));
26071 FILE* f = fopen("includepaths.txt", "r");
26072 if(f)
26073 {
26074 int32_t pos = 0;
26075 int32_t c;
26076 do
26077 {
26078 c = fgetc(f);
26079 if(c!=EOF)
26080 includePathString[pos++] = c;
26081 }
26082 while(c!=EOF && pos<MAX_INCLUDE_PATH_CHARS);
26083 if(pos<MAX_INCLUDE_PATH_CHARS)
26084 includePathString[pos] = '\0';
26085 includePathString[MAX_INCLUDE_PATH_CHARS-1] = '\0';
26086 fclose(f);
26087 }
26088 else strcpy(includePathString, "include/;headers/;scripts/;");
26089 al_trace("Full path string is: ");
26090 safe_al_trace(includePathString);
26091 al_trace("\n");
26092 updateIncludePaths();
26093
26094 for ( size_t q = 0; q < includePaths.size(); ++q )
26095 {
26096 al_trace("Include path %zu: ",q);
26097 safe_al_trace(includePaths.at(q).c_str());
26098 al_trace("\n");
26099 }
26100 }
26101
26102 int32_t FFScript::getQRBit(int32_t rule)
26103 {
26104 return ( get_qr(rule) ? 1 : 0 );
26105 }
26106
26107 int32_t FFScript::getTime(int32_t type)
26108 {
26109 //struct tm *tm_struct = localtime(time(NULL));
26110 struct tm * tm_struct;
26111 time_t rawtime;
26112 time (&rawtime);
26113 tm_struct = localtime (&rawtime);
26114
26115 switch(type)
26116 {
26117 case curyear:
26118 {
26119 int32_t year = tm_struct->tm_year + 1900; /* year */
26120 //year format starts at 1900, so we add it to the return
26121 return year;
26122
26123 }
26124 case curmonth:
26125 {
26126 int32_t month = tm_struct->tm_mon +1; /* month */
26127 //Months start at 0, but we want 1->12
26128 return month;
26129 }
26130 case curday_month:
26131 {
26132 int32_t day_month = tm_struct->tm_mday; /* day of the month */
26133 return day_month;
26134 }
26135 case curday_week:
26136 {
26137 int32_t day_week = tm_struct->tm_wday; /* day of the week */
26138 return day_week;
26139 }
26140 case curhour:
26141 {
26142 int32_t hour = tm_struct->tm_hour; /* hours */
26143 return hour;
26144 }
26145 case curminute:
26146 {
26147 int32_t minutes = tm_struct->tm_min; /* minutes */
26148 return minutes;
26149 }
26150 case cursecond:
26151 {
26152 int32_t secs = tm_struct->tm_sec; /* seconds */
26153 return secs;
26154 }
26155 case curdayyear:
26156 {
26157 int32_t day_year = tm_struct->tm_yday; /* day in the year */
26158 return day_year;
26159 }
26160 case curDST:
26161 {
26162 int32_t isDST = tm_struct->tm_isdst; /* daylight saving time */
26163 return isDST;
26164 }
26165 default: return -1;
26166
26167 }
26168 }
26169
26170 extern const char *itemclass_help_string_defaults[itype_max];
26171
26172 /* end */
26173
26174 24576 int32_t FFScript::getQuestHeaderInfo(int32_t type)
26175 {
26176 24576 return quest_format[type];
26177 }
26178
26179 bool isSideViewGravity(int32_t t)
26180 {
26181 return (Map.CurrScr()->flags7&fSIDEVIEW) != 0;
26182 }
26183
26184
26185
26186
26187 void FFScript::ZScriptConsole(bool open)
26188 {
26189
26190
26191 #ifdef _WIN32
26192 if ( console_is_open )
26193 {
26194 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200);
26195 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
26196 zscript_coloured_console.gotoxy(0,0);
26197 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
26198 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
26199 }
26200 else
26201 {
26202 //close
26203 zscript_coloured_console.Close();
26204 }
26205 #endif
26206 }
26207
26208 template <typename ...Params>
26209 void FFScript::ZScriptConsole(int32_t attributes,const char *format, Params&&... params)
26210 {
26211 #ifdef _WIN32
26212 initConsole();
26213 zscript_coloured_console.cprintf( attributes, format, std::forward<Params>(params)... );
26214 #endif
26215 }
26216
26217 int32_t getpitfall(int32_t x, int32_t y){return 0;}
26218
26219 bool update_hw_pal = false;
26220 void update_hw_screen()
26221 {
26222 if (is_headless())
26223 return;
26224
26225 framecnt++;
26226
26227 zc_process_display_events();
26228 if (update_hw_pal)
26229 {
26230 zc_set_palette(RAMpal);
26231 update_hw_pal = false;
26232 }
26233
26234 render_timer_wait();
26235 render_zq();
26236 }
26237
26238 bool checkCost(int32_t ctr, int32_t amnt)
26239 {
26240 if(!game) return true;
26241 if(amnt <= 0) return true;
26242 switch (ctr)
26243 {
26244 case crMONEY: //rupees
26245 {
26246 if ( current_item_power(itype_wallet) ) return true;
26247 break;
26248 }
26249 case crMAGIC: //magic
26250 {
26251 if (get_qr(qr_ENABLEMAGIC))
26252 {
26253 return (((current_item_power(itype_magicring) > 0)
26254 ? game->get_maxmagic()
26255 : game->get_magic()+game->get_dmagic())>=amnt*game->get_magicdrainrate());
26256 }
26257 return true;
26258 }
26259 case crARROWS:
26260 {
26261 if(current_item_power(itype_quiver))
26262 return true;
26263 if(!get_qr(qr_TRUEARROWS))
26264 return checkCost(crMONEY, amnt);
26265 break;
26266 }
26267 case crBOMBS:
26268 {
26269 if(current_item_power(itype_bombbag))
26270 return true;
26271 break;
26272 }
26273 case crSBOMBS:
26274 {
26275 if(current_item_power(itype_bombbag)
26276 && itemsbuf[current_item_id(itype_bombbag)].flags & item_flag1)
26277 return true;
26278 break;
26279 }
26280 }
26281 return (game->get_counter(ctr)+game->get_dcounter(ctr)>=amnt);
26282 }
26283 bool checkmagiccost(int32_t itemid, bool checkTime)
26284 {
26285 if(itemid < 0)
26286 {
26287 return false;
26288 }
26289 itemdata const& id = itemsbuf[itemid];
26290 return checkCost(id.cost_counter[0], id.cost_amount[0])
26291 && checkCost(id.cost_counter[1], id.cost_amount[1]);
26292 }
26293 bool checkbunny(int32_t itemid)
26294 {
26295 return true;
26296 }
26297
26298 void payCost(int32_t ctr, int32_t amnt, int32_t tmr, bool ignoreTimer)
26299 {
26300 return;
26301 }
26302 void paymagiccost(int32_t itemid, bool ignoreTimer, bool onlyTimer)
26303 {
26304 return;
26305 }
26306 bool is_in_scrolling_region()
26307 {
26308 return false;
26309 }
26310
26311 void enter_sys_pal(){}
26312 void exit_sys_pal(){}
26313
26314 void replay_step_comment(std::string comment) {}
26315 bool replay_is_active() {return false;}
26316 9 bool replay_is_replaying() {return false;}
26317 bool replay_version_check(int min, int max) {return false;}
26318 bool replay_is_debug() {return false;}
26319 std::string replay_get_meta_str(std::string key){return "";}
26320 int32_t item::run_script(int32_t mode){return 0;};
26321 ffcdata* slopes_getFFC(int id)
26322 {
26323 return nullptr;
26324 }
26325
26326 int calculate_test_dmap()
26327 {
26328 int dmap = -1;
26329 auto pal = Map.getcolor();
26330 int scr = Map.getCurrScr();
26331 int scrx = scr & 0x0F;
26332 for(auto q = 0; q < MAXDMAPS; ++q)
26333 {
26334 auto& dm = DMaps[q];
26335 if(dm.map != Map.getCurrMap())
26336 continue;
26337 if((dm.type&dmfTYPE)!=dmOVERW)
26338 {
26339 if(scrx < dm.xoff || scrx >= dm.xoff+8)
26340 continue;
26341 }
26342 if(dmap < 0)
26343 dmap = q; // soft-accept this, but look for better still
26344 if(pal == dm.color)
26345 {
26346 dmap = q;
26347 // found the best match we have information for, break out
26348 break;
26349 }
26350 }
26351 if(dmap < 0) dmap = 0;
26352 return dmap;
26353 }
26354
26355 #ifdef __EMSCRIPTEN__
26356 extern "C" void open_test_mode()
26357 {
26358 int dmap = calculate_test_dmap();
26359 int scr = zc_min(0x7F, Map.getCurrScr());
26360
26361 em_open_test_mode(filepath, dmap, scr, -1);
26362 }
26363
26364 extern "C" void get_shareable_url()
26365 {
26366 EM_ASM({
26367 ZC.setShareableUrl({open: UTF8ToString($0), map: $1, screen: $2});
26368 }, filepath, Map.getCurrMap(), Map.getCurrScr());
26369 }
26370 #endif
26371
26372 11 void setZScriptVersion(int32_t v){}
26373